Skip to content

Commit

Permalink
fix: debounce on wasm (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
DogeDark authored Jun 3, 2024
1 parent ffffa63 commit d49812f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 2 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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",
}
6 changes: 3 additions & 3 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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 }
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/utils/timing/debounce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ pub fn use_debounce<T>(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);
}));
}
Expand Down

0 comments on commit d49812f

Please sign in to comment.