From 50452e62b4df458d676fc95361b04ef2dd83aebf Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Mon, 4 Jan 2021 22:58:39 +0300 Subject: Update `tokio` to `1.0` --- futures/src/time.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'futures/src/time.rs') diff --git a/futures/src/time.rs b/futures/src/time.rs index 5e9ea436..7458af06 100644 --- a/futures/src/time.rs +++ b/futures/src/time.rs @@ -67,8 +67,20 @@ where let start = tokio::time::Instant::now() + self.0; - tokio::time::interval_at(start, self.0) - .map(|_| std::time::Instant::now()) - .boxed() + let stream = { + #[cfg(feature = "tokio")] + { + futures::stream::unfold( + tokio::time::interval_at(start, self.0), + |mut interval| async move { + Some((interval.tick().await, interval)) + }, + ) + } + #[cfg(feature = "tokio_old")] + tokio::time::interval_at(start, self.0) + }; + + stream.map(|_| std::time::Instant::now()).boxed() } } -- cgit From 09ea73bd2a43ecbcae56cb281aa8d0cce2d5f55d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 4 Jan 2021 23:19:15 +0100 Subject: Use `Instant::into_std` in `futures::time` --- futures/src/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'futures/src/time.rs') diff --git a/futures/src/time.rs b/futures/src/time.rs index 7458af06..d015d2f0 100644 --- a/futures/src/time.rs +++ b/futures/src/time.rs @@ -81,6 +81,6 @@ where tokio::time::interval_at(start, self.0) }; - stream.map(|_| std::time::Instant::now()).boxed() + stream.map(tokio::time::Instant::into_std).boxed() } } -- cgit From b2415eee61063d5c2b220d7b7a513d1952ce2be1 Mon Sep 17 00:00:00 2001 From: Jayce Fayne Date: Wed, 13 Jan 2021 01:48:35 +0100 Subject: Add `smol` async runtime --- futures/src/time.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'futures/src/time.rs') diff --git a/futures/src/time.rs b/futures/src/time.rs index d015d2f0..86b4a4e7 100644 --- a/futures/src/time.rs +++ b/futures/src/time.rs @@ -13,6 +13,33 @@ pub fn every( struct Every(std::time::Duration); +#[cfg(all( + not(any(feature = "tokio_old", feature = "tokio", feature = "async-std")), + feature = "smol" +))] +impl subscription::Recipe for Every +where + H: std::hash::Hasher, +{ + type Output = std::time::Instant; + + fn hash(&self, state: &mut H) { + use std::hash::Hash; + + std::any::TypeId::of::().hash(state); + self.0.hash(state); + } + + fn stream( + self: Box, + _input: futures::stream::BoxStream<'static, E>, + ) -> futures::stream::BoxStream<'static, Self::Output> { + use futures::stream::StreamExt; + + smol::Timer::interval(self.0).boxed() + } +} + #[cfg(feature = "async-std")] impl subscription::Recipe for Every where @@ -41,7 +68,7 @@ where #[cfg(all( any(feature = "tokio", feature = "tokio_old"), - not(feature = "async-std") + not(any(feature = "async-std", feature = "smol")) ))] impl subscription::Recipe for Every where -- cgit 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/src/time.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'futures/src/time.rs') 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 From 9da0a3de54e8e7161d4a3405633bc574ce43eb2d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 15 Jan 2021 21:07:37 +0100 Subject: Use `smol::Timer::interval` for `time::Every` --- futures/src/time.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'futures/src/time.rs') diff --git a/futures/src/time.rs b/futures/src/time.rs index c11942d2..86b4a4e7 100644 --- a/futures/src/time.rs +++ b/futures/src/time.rs @@ -35,16 +35,8 @@ where _input: futures::stream::BoxStream<'static, E>, ) -> futures::stream::BoxStream<'static, Self::Output> { use futures::stream::StreamExt; - use std::time::Instant; - 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() + smol::Timer::interval(self.0).boxed() } } -- cgit