diff options
Diffstat (limited to 'futures/src/backend/native')
-rw-r--r-- | futures/src/backend/native/async_std.rs | 3 | ||||
-rw-r--r-- | futures/src/backend/native/smol.rs | 3 | ||||
-rw-r--r-- | futures/src/backend/native/tokio.rs | 17 |
3 files changed, 11 insertions, 12 deletions
diff --git a/futures/src/backend/native/async_std.rs b/futures/src/backend/native/async_std.rs index 52b0e914..b7da5e90 100644 --- a/futures/src/backend/native/async_std.rs +++ b/futures/src/backend/native/async_std.rs @@ -18,8 +18,7 @@ impl crate::Executor for Executor { pub mod time { //! Listen and react to time. - use crate::core::Hasher; - use crate::subscription::{self, Subscription}; + use crate::subscription::{self, Hasher, Subscription}; /// Returns a [`Subscription`] that produces messages at a set interval. /// diff --git a/futures/src/backend/native/smol.rs b/futures/src/backend/native/smol.rs index 00d13d35..aaf1518c 100644 --- a/futures/src/backend/native/smol.rs +++ b/futures/src/backend/native/smol.rs @@ -17,8 +17,7 @@ impl crate::Executor for Executor { pub mod time { //! Listen and react to time. - use crate::core::Hasher; - use crate::subscription::{self, Subscription}; + use crate::subscription::{self, Hasher, Subscription}; /// Returns a [`Subscription`] that produces messages at a set interval. /// diff --git a/futures/src/backend/native/tokio.rs b/futures/src/backend/native/tokio.rs index 4698a105..df91d798 100644 --- a/futures/src/backend/native/tokio.rs +++ b/futures/src/backend/native/tokio.rs @@ -22,8 +22,7 @@ impl crate::Executor for Executor { pub mod time { //! Listen and react to time. - use crate::core::Hasher; - use crate::subscription::{self, Subscription}; + use crate::subscription::{self, Hasher, Subscription}; /// Returns a [`Subscription`] that produces messages at a set interval. /// @@ -56,13 +55,15 @@ pub mod time { let start = tokio::time::Instant::now() + self.0; + let mut interval = tokio::time::interval_at(start, self.0); + interval.set_missed_tick_behavior( + tokio::time::MissedTickBehavior::Skip, + ); + let stream = { - futures::stream::unfold( - tokio::time::interval_at(start, self.0), - |mut interval| async move { - Some((interval.tick().await, interval)) - }, - ) + futures::stream::unfold(interval, |mut interval| async move { + Some((interval.tick().await, interval)) + }) }; stream.map(tokio::time::Instant::into_std).boxed() |