From fd2c96c8e36eb37ea4a53aafe0986b569a4e3753 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 15 Jan 2021 18:52:12 +0100 Subject: Fix `time::Every` implementation for `smol` runtime --- futures/Cargo.toml | 2 +- futures/src/time.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'futures') diff --git a/futures/Cargo.toml b/futures/Cargo.toml index c42cc603..c266f705 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -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] diff --git a/futures/src/time.rs b/futures/src/time.rs index 86b4a4e7..c11942d2 100644 --- a/futures/src/time.rs +++ b/futures/src/time.rs @@ -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() } } -- cgit