summaryrefslogtreecommitdiffstats
path: root/futures
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-11 01:27:51 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-11 01:27:51 +0100
commitf37d068af52700570f863960c3432df85a244a7c (patch)
tree464cbe91785db3c1c9924e2f2d1df6ce008aa914 /futures
parent05618ea9b39048ca905918682e99c2d139683078 (diff)
downloadiced-f37d068af52700570f863960c3432df85a244a7c.tar.gz
iced-f37d068af52700570f863960c3432df85a244a7c.tar.bz2
iced-f37d068af52700570f863960c3432df85a244a7c.zip
Rewrite `websocket` example using `sipper`
Diffstat (limited to 'futures')
-rw-r--r--futures/src/backend/native/tokio.rs11
-rw-r--r--futures/src/lib.rs1
2 files changed, 5 insertions, 7 deletions
diff --git a/futures/src/backend/native/tokio.rs b/futures/src/backend/native/tokio.rs
index e0be83a6..c38ef566 100644
--- a/futures/src/backend/native/tokio.rs
+++ b/futures/src/backend/native/tokio.rs
@@ -23,11 +23,10 @@ impl crate::Executor for Executor {
pub mod time {
//! Listen and react to time.
use crate::core::time::{Duration, Instant};
- use crate::stream;
use crate::subscription::Subscription;
use crate::MaybeSend;
- use futures::SinkExt;
+ use futures::stream;
use std::future::Future;
/// Returns a [`Subscription`] that produces messages at a set interval.
@@ -66,12 +65,12 @@ pub mod time {
let f = *f;
let interval = *interval;
- stream::channel(1, move |mut output| async move {
- loop {
- let _ = output.send(f().await).await;
-
+ stream::unfold(0, move |i| async move {
+ if i > 0 {
tokio::time::sleep(interval).await;
}
+
+ Some((f().await, i + 1))
})
})
}
diff --git a/futures/src/lib.rs b/futures/src/lib.rs
index 31738823..a874a618 100644
--- a/futures/src/lib.rs
+++ b/futures/src/lib.rs
@@ -15,7 +15,6 @@ pub mod backend;
pub mod event;
pub mod executor;
pub mod keyboard;
-pub mod stream;
pub mod subscription;
pub use executor::Executor;