|
1 | | -use std::cell::RefCell; |
2 | 1 | use std::future::Future;
|
3 | 2 |
|
4 | | -static GLOBAL_EXECUTOR: once_cell::sync::Lazy<async_executor::Executor> = once_cell::sync::Lazy::new(async_executor::Executor::new); |
5 | | - |
6 | | -thread_local! { |
7 | | - static EXECUTOR: RefCell<async_executor::LocalExecutor> = RefCell::new(async_executor::LocalExecutor::new()); |
8 | | -} |
9 | | - |
10 | | -pub(crate) fn spawn<F, T>(future: F) -> async_executor::Task<T> |
11 | | -where |
12 | | - F: Future<Output = T> + Send + 'static, |
13 | | - T: Send + 'static, |
14 | | -{ |
15 | | - GLOBAL_EXECUTOR.spawn(future) |
16 | | -} |
17 | | - |
18 | | -#[cfg(feature = "unstable")] |
19 | | -pub(crate) fn local<F, T>(future: F) -> async_executor::Task<T> |
20 | | -where |
21 | | - F: Future<Output = T> + 'static, |
22 | | - T: 'static, |
23 | | -{ |
24 | | - EXECUTOR.with(|executor| executor.borrow().spawn(future)) |
25 | | -} |
26 | | - |
27 | 3 | pub(crate) fn run<F, T>(future: F) -> T
|
28 | 4 | where
|
29 | 5 | F: Future<Output = T>,
|
30 | 6 | {
|
31 | | - EXECUTOR.with(|executor| enter(|| async_io::block_on(executor.borrow().run(future)))) |
32 | | -} |
33 | | - |
34 | | -pub(crate) fn run_global<F, T>(future: F) -> T |
35 | | -where |
36 | | - F: Future<Output = T>, |
37 | | -{ |
38 | | - enter(|| async_io::block_on(GLOBAL_EXECUTOR.run(future))) |
| 7 | + enter(|| async_global_executor::block_on(future)) |
39 | 8 | }
|
40 | 9 |
|
41 | 10 | /// Enters the tokio context if the `tokio` feature is enabled.
|
|
0 commit comments