Skip to content

Commit

Permalink
Fix time::Every implementation for smol runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jan 15, 2021
1 parent bcc54b0 commit fd2c96c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/stopwatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2018"
publish = false

[dependencies]
iced = { path = "../..", features = ["tokio"] }
iced = { path = "../..", features = ["smol"] }
2 changes: 1 addition & 1 deletion futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ optional = true
features = ["unstable"]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies.smol]
version = "1.0"
version = "1.2"
optional = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
10 changes: 9 additions & 1 deletion futures/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ where
_input: futures::stream::BoxStream<'static, E>,
) -> futures::stream::BoxStream<'static, Self::Output> {
use futures::stream::StreamExt;
use std::time::Instant;

smol::Timer::interval(self.0).boxed()
let duration = self.0;

futures::stream::unfold(Instant::now(), move |last_tick| async move {
let last_tick = smol::Timer::at(last_tick + duration).await;

Some((last_tick, last_tick))
})
.boxed()
}
}

Expand Down

0 comments on commit fd2c96c

Please sign in to comment.