From d49812fbc9d4506bd3b1ec994f45ef4447f34c79 Mon Sep 17 00:00:00 2001 From: Miles Murgaw Date: Mon, 3 Jun 2024 14:28:13 -0400 Subject: [PATCH] fix: debounce on wasm (#45) --- .vscode/settings.json | 7 ++----- sdk/Cargo.toml | 6 +++--- sdk/src/utils/timing/debounce.rs | 5 +++++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 926459a..3bfb25c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,6 @@ { "rust-analyzer.cargo.features": [ - "desktop-testing" + "wasm-testing" ], - "rust-analyzer.cargo.extraArgs": [ - "--exclude=color_scheme" - ], - //"rust-analyzer.cargo.target": "wasm32-unknown-unknown", + "rust-analyzer.cargo.target": "wasm32-unknown-unknown", } \ No newline at end of file diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index cac84b2..eb5b67a 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -151,9 +151,6 @@ dioxus-signals = { version = "0.5.0-alpha.2", features = [ yazi = { version = "0.1.4", optional = true } tracing = "0.1.40" -# Used by: timing -gloo-timers = { version = "0.3.0", optional = true } - # Used by: timing & storage tokio = { version = "1.33.0", optional = true } @@ -184,6 +181,9 @@ js-sys = "0.3.62" # Used by: channel uuid = { version = "1.3.2", features = ["js"] } +# Used by: timing +gloo-timers = { version = "0.3.0", optional = true, features = ["futures"] } + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] # Used by: storage directories = { version = "4.0.1", optional = true } diff --git a/sdk/src/utils/timing/debounce.rs b/sdk/src/utils/timing/debounce.rs index 6f62fa6..d6acbaf 100644 --- a/sdk/src/utils/timing/debounce.rs +++ b/sdk/src/utils/timing/debounce.rs @@ -77,7 +77,12 @@ pub fn use_debounce(time: Duration, cb: impl FnOnce(T) + Copy + 'static) -> U } current_task = Some(spawn(async move { + #[cfg(not(target_family = "wasm"))] tokio::time::sleep(time).await; + + #[cfg(target_family = "wasm")] + gloo_timers::future::sleep(time).await; + cb(data); })); }