diff --git a/src/config.rs b/src/config.rs index 339b201..81a806e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -89,8 +89,8 @@ pub fn process_tile( ) -> BoxStream<'static, Result>> { let five_secs = time::Duration::from_secs(5); match tile { - TileConfig::Load => Box::pin(tiles::load_stream(time::interval(five_secs))), - TileConfig::Memory => Box::pin(tiles::memory_stream(time::interval(five_secs))), + TileConfig::Load => Box::pin(time::throttle(five_secs, tiles::load_stream())), + TileConfig::Memory => Box::pin(time::throttle(five_secs, tiles::memory_stream())), TileConfig::Hostname => Box::pin(tiles::hostname_stream()), TileConfig::Time(c) => Box::pin(tiles::time_stream(c.clone())), } diff --git a/src/tiles/load.rs b/src/tiles/load.rs index e7d686b..d6f5016 100644 --- a/src/tiles/load.rs +++ b/src/tiles/load.rs @@ -4,13 +4,9 @@ use tokio::fs::File; use tokio::prelude::*; use tokio::stream::Stream; -pub fn load_stream( - clock: T, -) -> impl Stream>> -where - T: Stream, +pub fn load_stream() -> impl Stream>> { - clock.then(|_| async { + futures::stream::repeat(()).then(|()| async { let mut raw = String::new(); File::open("/proc/loadavg") .await? diff --git a/src/tiles/memory.rs b/src/tiles/memory.rs index d34087a..72dbf04 100644 --- a/src/tiles/memory.rs +++ b/src/tiles/memory.rs @@ -1,7 +1,6 @@ use crate::tile::Block; -use futures::{Stream, StreamExt}; -use std::io; -use std::str; +use futures::{stream, Stream, StreamExt}; +use std::{io, str, u64}; use tokio::fs::File; use tokio::prelude::*; @@ -41,13 +40,9 @@ fn extract_value(line: &str) -> Result( - clock: T, -) -> impl Stream>> -where - T: Stream, +pub fn memory_stream() -> impl Stream>> { - clock.then(|_| async { + stream::repeat(()).then(|_| async { let mut raw = [0u8; 256]; File::open("/proc/meminfo") .await? diff --git a/src/tiles/time.rs b/src/tiles/time.rs index b523d4a..686aa25 100644 --- a/src/tiles/time.rs +++ b/src/tiles/time.rs @@ -49,7 +49,7 @@ impl Stream for TimeStream { type Item = Result>; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let project = Pin::as_mut(&mut self).project(); - let () = ready!(Future::poll(project.delay, cx)); + ready!(Future::poll(project.delay, cx)); let now = Local::now(); Pin::as_mut(&mut self)