From 50452e62b4df458d676fc95361b04ef2dd83aebf Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Mon, 4 Jan 2021 22:58:39 +0300 Subject: [PATCH 1/2] Update `tokio` to `1.0` --- examples/game_of_life/Cargo.toml | 2 +- futures/Cargo.toml | 5 +++-- futures/src/time.rs | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/examples/game_of_life/Cargo.toml b/examples/game_of_life/Cargo.toml index 9c4172c42c..ffd2f19ef4 100644 --- a/examples/game_of_life/Cargo.toml +++ b/examples/game_of_life/Cargo.toml @@ -7,6 +7,6 @@ publish = false [dependencies] iced = { path = "../..", features = ["canvas", "tokio", "debug"] } -tokio = { version = "0.3", features = ["sync"] } +tokio = { version = "1.0", features = ["sync"] } itertools = "0.9" rustc-hash = "1.1" diff --git a/futures/Cargo.toml b/futures/Cargo.toml index e8e47c0881..92b504a6e9 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -26,9 +26,10 @@ optional = true features = ["rt-core", "rt-threaded", "time", "stream"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.tokio] -version = "0.3" +package = "tokio" +version = "1.0" optional = true -features = ["rt-multi-thread", "time", "stream"] +features = ["rt", "rt-multi-thread", "time"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.async-std] version = "1.0" diff --git a/futures/src/time.rs b/futures/src/time.rs index 5e9ea436a5..7458af06b0 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() } } From 09ea73bd2a43ecbcae56cb281aa8d0cce2d5f55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Mon, 4 Jan 2021 23:19:15 +0100 Subject: [PATCH 2/2] Use `Instant::into_std` in `futures::time` --- futures/src/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/futures/src/time.rs b/futures/src/time.rs index 7458af06b0..d015d2f0e0 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() } }