refactor: split info_stream into module
in preparation to create a client-server model
This commit is contained in:
parent
534b6cde99
commit
171194e99f
1 changed files with 31 additions and 23 deletions
28
src/app/info_stream.rs
Normal file
28
src/app/info_stream.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use iced::{
|
||||
futures::{self, SinkExt},
|
||||
stream,
|
||||
};
|
||||
use smol::Timer;
|
||||
|
||||
use crate::sysinfo_snapshot::SysinfoSnapshot;
|
||||
|
||||
pub fn create() -> impl futures::Stream<Item = SysinfoSnapshot> {
|
||||
stream::channel(
|
||||
1,
|
||||
async |mut sender: futures::channel::mpsc::Sender<SysinfoSnapshot>| {
|
||||
let mut sys = sysinfo::System::new();
|
||||
let refreshes = sysinfo::RefreshKind::nothing()
|
||||
.with_memory(sysinfo::MemoryRefreshKind::everything())
|
||||
.with_cpu(sysinfo::CpuRefreshKind::nothing().with_cpu_usage());
|
||||
|
||||
sys.refresh_specifics(refreshes);
|
||||
Timer::after(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL).await;
|
||||
|
||||
loop {
|
||||
sys.refresh_specifics(refreshes);
|
||||
sender.send(SysinfoSnapshot::from(&sys)).await.unwrap();
|
||||
Timer::after(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL).await;
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
Loading…
Reference in a new issue