Fix `time::Every` implementation for `smol` runtime

This commit is contained in:
Héctor Ramón Jiménez 2021-01-15 18:52:12 +01:00
parent bcc54b0831
commit fd2c96c8e3
3 changed files with 11 additions and 3 deletions

View File

@ -6,4 +6,4 @@ edition = "2018"
publish = false publish = false
[dependencies] [dependencies]
iced = { path = "../..", features = ["tokio"] } iced = { path = "../..", features = ["smol"] }

View File

@ -37,7 +37,7 @@ optional = true
features = ["unstable"] features = ["unstable"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.smol] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.smol]
version = "1.0" version = "1.2"
optional = true optional = true
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]

View File

@ -35,8 +35,16 @@ where
_input: futures::stream::BoxStream<'static, E>, _input: futures::stream::BoxStream<'static, E>,
) -> futures::stream::BoxStream<'static, Self::Output> { ) -> futures::stream::BoxStream<'static, Self::Output> {
use futures::stream::StreamExt; 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()
} }
} }