Rewrite websocket example using sipper
This commit is contained in:
parent
05618ea9b3
commit
f37d068af5
4 changed files with 45 additions and 70 deletions
|
|
@ -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))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue