Rewrite websocket example using sipper

This commit is contained in:
Héctor Ramón Jiménez 2025-02-11 01:27:51 +01:00
parent 05618ea9b3
commit f37d068af5
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
4 changed files with 45 additions and 70 deletions

View file

@ -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))
})
})
}

View file

@ -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;