don't use futures-executor when it's not the default executor

This commit is contained in:
edwloef 2025-03-13 23:12:44 +01:00 committed by Héctor Ramón Jiménez
parent a3a7503eef
commit baadcc150f
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
12 changed files with 41 additions and 12 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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);
}