don't use futures-executor when it's not the default executor
This commit is contained in:
parent
a3a7503eef
commit
baadcc150f
12 changed files with 41 additions and 12 deletions
|
|
@ -13,6 +13,10 @@ impl crate::Executor for Executor {
|
|||
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
||||
let _ = async_std::task::spawn(future);
|
||||
}
|
||||
|
||||
fn block_on(future: impl Future<Output = ()> + 'static) {
|
||||
async_std::task::block_on(future);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ impl crate::Executor for Executor {
|
|||
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
||||
smol::spawn(future).detach();
|
||||
}
|
||||
|
||||
fn block_on(future: impl Future<Output = ()> + 'static) {
|
||||
smol::block_on(future);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ impl crate::Executor for Executor {
|
|||
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
||||
self.spawn_ok(future);
|
||||
}
|
||||
|
||||
fn block_on(future: impl Future<Output = ()> + 'static) {
|
||||
futures::executor::block_on(future);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,13 @@ impl crate::Executor for Executor {
|
|||
let _guard = tokio::runtime::Runtime::enter(self);
|
||||
f()
|
||||
}
|
||||
|
||||
fn block_on(future: impl Future<Output = ()> + 'static) {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(future);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,12 @@ impl crate::Executor for Executor {
|
|||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn spawn(&self, _future: impl Future<Output = ()> + 'static) {}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn block_on(_future: impl Future<Output = ()> + 'static) {}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn block_on(_future: impl Future<Output = ()> + 'static) {}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ impl crate::Executor for Executor {
|
|||
fn spawn(&self, future: impl futures::Future<Output = ()> + 'static) {
|
||||
wasm_bindgen_futures::spawn_local(future);
|
||||
}
|
||||
|
||||
fn block_on(future: impl futures::Future<Output = ()> + 'static) {
|
||||
wasm_bindgen_futures::spawn_local(future);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod time {
|
||||
|
|
|
|||
|
|
@ -20,4 +20,7 @@ pub trait Executor: Sized {
|
|||
fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
|
||||
f()
|
||||
}
|
||||
|
||||
/// Runs the future on the current thread, blocking it until it is completed.
|
||||
fn block_on(future: impl Future<Output = ()> + 'static);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue