diff options
author | 2025-02-02 22:44:05 -0300 | |
---|---|---|
committer | 2025-02-02 22:44:05 -0300 | |
commit | 6a584af1411b713fab52400712031bfa82bccd18 (patch) | |
tree | cddab91bcd26390a4d78f8176e6e9c5b3774ce84 | |
parent | 599d8b560bec8036c5ddda62a7bf0a540bdec396 (diff) | |
download | iced-6a584af1411b713fab52400712031bfa82bccd18.tar.gz iced-6a584af1411b713fab52400712031bfa82bccd18.tar.bz2 iced-6a584af1411b713fab52400712031bfa82bccd18.zip |
Use working wasmtimer for time::every
-rw-r--r-- | Cargo.lock | 57 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | examples/todos/Cargo.toml | 2 | ||||
-rw-r--r-- | examples/todos/src/main.rs | 3 | ||||
-rw-r--r-- | futures/Cargo.toml | 2 | ||||
-rw-r--r-- | futures/src/backend/wasm/wasm_bindgen.rs | 45 |
6 files changed, 33 insertions, 78 deletions
@@ -2535,7 +2535,7 @@ dependencies = [ "smol", "tokio", "wasm-bindgen-futures", - "wasm-timer", + "wasmtimer", ] [[package]] @@ -4114,37 +4114,12 @@ checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" [[package]] name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - -[[package]] -name = "parking_lot" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", - "parking_lot_core 0.9.10", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] @@ -4667,15 +4642,6 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_syscall" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" @@ -5813,7 +5779,7 @@ dependencies = [ "serde_json", "tracing-subscriber", "uuid", - "wasm-timer", + "wasmtimer", "web-sys", ] @@ -6459,18 +6425,17 @@ dependencies = [ ] [[package]] -name = "wasm-timer" -version = "0.2.5" +name = "wasmtimer" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" +checksum = "0048ad49a55b9deb3953841fa1fc5858f0efbcb7a18868c899a360269fac1b23" dependencies = [ "futures", "js-sys", - "parking_lot 0.11.2", + "parking_lot", "pin-utils", + "slab", "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", ] [[package]] @@ -6657,7 +6622,7 @@ dependencies = [ "js-sys", "log", "naga", - "parking_lot 0.12.3", + "parking_lot", "profiling", "raw-window-handle 0.6.2", "smallvec", @@ -6685,7 +6650,7 @@ dependencies = [ "log", "naga", "once_cell", - "parking_lot 0.12.3", + "parking_lot", "profiling", "raw-window-handle 0.6.2", "rustc-hash 1.1.0", @@ -6725,7 +6690,7 @@ dependencies = [ "ndk-sys 0.5.0+25.2.9519653", "objc", "once_cell", - "parking_lot 0.12.3", + "parking_lot", "profiling", "range-alloc", "raw-window-handle 0.6.2", @@ -184,7 +184,7 @@ tracing = "0.1" unicode-segmentation = "1.0" url = "2.5" wasm-bindgen-futures = "0.4" -wasm-timer = "0.2" +wasmtimer = "0.4.1" web-sys = "0.3.69" web-time = "1.1" wgpu = "23.0" diff --git a/examples/todos/Cargo.toml b/examples/todos/Cargo.toml index 5d42a88d..2b49e4e9 100644 --- a/examples/todos/Cargo.toml +++ b/examples/todos/Cargo.toml @@ -24,7 +24,7 @@ iced.features = ["debug", "webgl", "fira-sans"] uuid = { version = "1.0", features = ["js"] } web-sys = { workspace = true, features = ["Window", "Storage"] } -wasm-timer.workspace = true +wasmtimer.workspace = true [dev-dependencies] iced_test.workspace = true diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 7faf742e..74c4c464 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -578,7 +578,8 @@ impl SavedState { .set_item("state", &json) .map_err(|_| SaveError::Write)?; - let _ = wasm_timer::Delay::new(std::time::Duration::from_secs(2)).await; + let _ = + wasmtimer::tokio::sleep(std::time::Duration::from_secs(2)).await; Ok(()) } diff --git a/futures/Cargo.toml b/futures/Cargo.toml index a6fcfde1..3984ce83 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -41,4 +41,4 @@ tokio.features = ["rt", "rt-multi-thread", "time"] [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen-futures.workspace = true -wasm-timer.workspace = true +wasmtimer.workspace = true diff --git a/futures/src/backend/wasm/wasm_bindgen.rs b/futures/src/backend/wasm/wasm_bindgen.rs index f7846c01..4811e7f4 100644 --- a/futures/src/backend/wasm/wasm_bindgen.rs +++ b/futures/src/backend/wasm/wasm_bindgen.rs @@ -16,41 +16,30 @@ impl crate::Executor for Executor { pub mod time { //! Listen and react to time. - use crate::subscription::{self, Hasher, Subscription}; - use crate::BoxStream; + use crate::subscription::Subscription; + + use wasmtimer::std::Instant; /// Returns a [`Subscription`] that produces messages at a set interval. /// /// The first message is produced after a `duration`, and then continues to /// produce more messages every `duration` after that. - pub fn every( - duration: std::time::Duration, - ) -> Subscription<wasm_timer::Instant> { - subscription::from_recipe(Every(duration)) - } - - #[derive(Debug)] - struct Every(std::time::Duration); - - impl subscription::Recipe for Every { - type Output = wasm_timer::Instant; - - fn hash(&self, state: &mut Hasher) { - use std::hash::Hash; + pub fn every(duration: std::time::Duration) -> Subscription<Instant> { + Subscription::run_with(duration, |duration| { + use futures::stream::StreamExt; - std::any::TypeId::of::<Self>().hash(state); - self.0.hash(state); - } + let mut interval = wasmtimer::tokio::interval(*duration); + interval.set_missed_tick_behavior( + wasmtimer::tokio::MissedTickBehavior::Skip, + ); - fn stream( - self: Box<Self>, - _input: subscription::EventStream, - ) -> BoxStream<Self::Output> { - use futures::stream::StreamExt; + let stream = { + futures::stream::unfold(interval, |mut interval| async move { + Some((interval.tick().await, interval)) + }) + }; - wasm_timer::Interval::new(self.0) - .map(|_| wasm_timer::Instant::now()) - .boxed_local() - } + stream.boxed() + }) } } |