summaryrefslogtreecommitdiffstats
path: root/futures/src/time.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2021-01-15 19:04:23 +0100
committerLibravatar GitHub <noreply@github.com>2021-01-15 19:04:23 +0100
commit2056304e39c32ef5613eb6e82036586043002c08 (patch)
treed6f780a018222ed4a4476cfbc634543c7499b462 /futures/src/time.rs
parent984583b0cca86d7ba8f865489cbebeb181349c19 (diff)
parentfd2c96c8e36eb37ea4a53aafe0986b569a4e3753 (diff)
downloadiced-2056304e39c32ef5613eb6e82036586043002c08.tar.gz
iced-2056304e39c32ef5613eb6e82036586043002c08.tar.bz2
iced-2056304e39c32ef5613eb6e82036586043002c08.zip
Merge pull request #699 from JayceFayne/smol
Add `smol` async runtime support
Diffstat (limited to '')
-rw-r--r--futures/src/time.rs37
1 files changed, 36 insertions, 1 deletions
diff --git a/futures/src/time.rs b/futures/src/time.rs
index d015d2f0..c11942d2 100644
--- a/futures/src/time.rs
+++ b/futures/src/time.rs
@@ -13,6 +13,41 @@ pub fn every<H: std::hash::Hasher, E>(
struct Every(std::time::Duration);
+#[cfg(all(
+ not(any(feature = "tokio_old", feature = "tokio", feature = "async-std")),
+ feature = "smol"
+))]
+impl<H, E> subscription::Recipe<H, E> 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::<Self>().hash(state);
+ self.0.hash(state);
+ }
+
+ fn stream(
+ self: Box<Self>,
+ _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()
+ }
+}
+
#[cfg(feature = "async-std")]
impl<H, E> subscription::Recipe<H, E> for Every
where
@@ -41,7 +76,7 @@ where
#[cfg(all(
any(feature = "tokio", feature = "tokio_old"),
- not(feature = "async-std")
+ not(any(feature = "async-std", feature = "smol"))
))]
impl<H, E> subscription::Recipe<H, E> for Every
where