mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-27 09:54:41 -05:00
fix: revert back tick implementation to respect global executor
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -865,7 +865,6 @@ mod tests {
|
||||
}
|
||||
});
|
||||
tick().await;
|
||||
tick().await;
|
||||
store.user().set("Greg".into());
|
||||
tick().await;
|
||||
store.user().set("Carol".into());
|
||||
|
||||
Reference in New Issue
Block a user