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