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') 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') 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/executor.rs | 6 ++++++ futures/src/executor/smol.rs | 18 ++++++++++++++++++ futures/src/lib.rs | 16 ++++++++++++++-- futures/src/time.rs | 29 ++++++++++++++++++++++++++++- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 futures/src/executor/smol.rs (limited to 'futures/src') diff --git a/futures/src/executor.rs b/futures/src/executor.rs index fa87216a..b35b5bc1 100644 --- a/futures/src/executor.rs +++ b/futures/src/executor.rs @@ -13,6 +13,9 @@ mod tokio_old; #[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))] mod async_std; +#[cfg(all(not(target_arch = "wasm32"), feature = "smol"))] +mod smol; + #[cfg(target_arch = "wasm32")] mod wasm_bindgen; @@ -30,6 +33,9 @@ pub use self::tokio_old::TokioOld; #[cfg(all(not(target_arch = "wasm32"), feature = "async-std"))] pub use self::async_std::AsyncStd; +#[cfg(all(not(target_arch = "wasm32"), feature = "smol"))] +pub use self::smol::Smol; + #[cfg(target_arch = "wasm32")] pub use wasm_bindgen::WasmBindgen; diff --git a/futures/src/executor/smol.rs b/futures/src/executor/smol.rs new file mode 100644 index 00000000..deafd43a --- /dev/null +++ b/futures/src/executor/smol.rs @@ -0,0 +1,18 @@ +use crate::Executor; + +use futures::Future; + +/// A `smol` runtime. +#[cfg_attr(docsrs, doc(cfg(feature = "smol")))] +#[derive(Debug)] +pub struct Smol; + +impl Executor for Smol { + fn new() -> Result { + Ok(Self) + } + + fn spawn(&self, future: impl Future + Send + 'static) { + smol::spawn(future).detach(); + } +} diff --git a/futures/src/lib.rs b/futures/src/lib.rs index c7c6fd3a..01cf5c89 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -17,10 +17,22 @@ pub mod executor; pub mod subscription; #[cfg(all( - any(feature = "tokio", feature = "tokio_old", feature = "async-std"), + any( + feature = "tokio", + feature = "tokio_old", + feature = "async-std", + feature = "smol" + ), not(target_arch = "wasm32") ))] -#[cfg_attr(docsrs, doc(cfg(any(feature = "tokio", feature = "async-std"))))] +#[cfg_attr( + docsrs, + doc(cfg(any( + feature = "tokio", + feature = "async-std", + feature = "smol" + ))) +)] pub mod time; pub use command::Command; 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') 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') 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 From 6759a5c56fc53286d77698ac9a86812b6d7b03ff Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 23 Feb 2021 02:16:12 +0100 Subject: Log event subscription error as a warning --- futures/src/subscription/tracker.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'futures/src') diff --git a/futures/src/subscription/tracker.rs b/futures/src/subscription/tracker.rs index 43222b5b..3a8d4a87 100644 --- a/futures/src/subscription/tracker.rs +++ b/futures/src/subscription/tracker.rs @@ -135,7 +135,7 @@ where .filter_map(|connection| connection.listener.as_mut()) .for_each(|listener| { if let Err(error) = listener.try_send(event.clone()) { - log::error!( + log::warn!( "Error sending event to subscription: {:?}", error ); -- cgit From 83d19689c80266874e0a26085f17a94fd3507e1e Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Mon, 14 Jun 2021 21:01:37 +0300 Subject: docs: update all 0.2 github links to 0.3 --- futures/src/subscription.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'futures/src') diff --git a/futures/src/subscription.rs b/futures/src/subscription.rs index 27d2d295..e60ad79a 100644 --- a/futures/src/subscription.rs +++ b/futures/src/subscription.rs @@ -125,9 +125,9 @@ impl std::fmt::Debug for Subscription { /// - [`stopwatch`], a watch with start/stop and reset buttons showcasing how /// to listen to time. /// -/// [examples]: https://github.com/hecrj/iced/tree/0.2/examples -/// [`download_progress`]: https://github.com/hecrj/iced/tree/0.2/examples/download_progress -/// [`stopwatch`]: https://github.com/hecrj/iced/tree/0.2/examples/stopwatch +/// [examples]: https://github.com/hecrj/iced/tree/0.3/examples +/// [`download_progress`]: https://github.com/hecrj/iced/tree/0.3/examples/download_progress +/// [`stopwatch`]: https://github.com/hecrj/iced/tree/0.3/examples/stopwatch pub trait Recipe { /// The events that will be produced by a [`Subscription`] with this /// [`Recipe`]. -- cgit