This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add feature to control async runtime.
fix #152 Signed-off-by: Yang, Longlong <[email protected]>
- Loading branch information
1 parent
d516783
commit 0189b3c
Showing
12 changed files
with
120 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2023 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 or MIT | ||
|
||
extern crate alloc; | ||
use alloc::boxed::Box; | ||
use core::{future::Future, pin::Pin}; | ||
|
||
// Run async task | ||
pub fn block_on<T>(future: Pin<Box<dyn Future<Output = T> + 'static + Send>>) -> T | ||
where | ||
T: Send + 'static, | ||
{ | ||
#[cfg(all(feature = "async-executor", feature = "async-tokio"))] | ||
compile_error!("features `async-executor` and `async-tokio` are mutually exclusive"); | ||
|
||
if cfg!(feature = "async-executor") { | ||
executor::block_on(future) | ||
} else if cfg!(feature = "async-tokio") { | ||
let rt = tokio::runtime::Runtime::new().unwrap(); | ||
|
||
rt.block_on(future) | ||
} else { | ||
panic!("Calling block_on require one of `async-executor` or `async-tokio` is enabled!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.