fix: revert back tick implementation to respect global executor

This commit is contained in:
Saber Haj Rabiee
2025-03-29 06:09:27 -07:00
parent 02f4cfe437
commit ae373b5a52
4 changed files with 15 additions and 15 deletions

View File

@@ -11,7 +11,6 @@ edition.workspace = true
[dependencies]
async-executor = { version = "1.13.1", optional = true }
futures = "0.3.31"
futures-lite = { version = "2.6.0", default-features = false }
glib = { version = "0.20.6", optional = true }
thiserror = "2.0"
tokio = { version = "1.41", optional = true, default-features = false, features = [
@@ -21,6 +20,7 @@ tracing = { version = "0.1.41", optional = true }
wasm-bindgen-futures = { version = "0.4.50", optional = true }
[dev-dependencies]
futures-lite = { version = "2.6.0", default-features = false }
tokio = { version = "1.41", default-features = false, features = [
"rt",
"macros",

View File

@@ -138,11 +138,20 @@ impl Executor {
}
/// Waits until the next "tick" of the current async executor.
/// Respects the global executor.
#[inline(always)]
pub async fn tick() {
// We are already running this async function in the executor, no need to use
// spawn/spawn_local
futures_lite::future::yield_now().await;
let (tx, rx) = futures::channel::oneshot::channel();
#[cfg(not(all(feature = "wasm-bindgen", target_family = "wasm")))]
Executor::spawn(async move {
_ = tx.send(());
});
#[cfg(all(feature = "wasm-bindgen", target_family = "wasm"))]
Executor::spawn_local(async move {
_ = tx.send(());
});
_ = rx.await;
}
/// Polls the global async executor.

View File

@@ -82,15 +82,7 @@ fn test_wasm_bindgen_spawn_errors() {
let _ = Executor::init_wasm_bindgen();
// Using should_panic to test that Executor::spawn panics in wasm
// Note: We can't use #[should_panic] with async tests, so we test synchronously
let result = std::panic::catch_unwind(|| {
Executor::spawn(async {
// This should panic since wasm-bindgen doesn't support Send futures
});
Executor::spawn(async {
// This should panic since wasm-bindgen doesn't support Send futures
});
assert!(
result.is_err(),
"Expected Executor::spawn to panic in wasm environment"
);
}

View File

@@ -865,7 +865,6 @@ mod tests {
}
});
tick().await;
tick().await;
store.user().set("Greg".into());
tick().await;
store.user().set("Carol".into());