Run system::information in a different thread

... since it seems it can block for a couple of seconds.
This commit is contained in:
Héctor Ramón Jiménez 2022-05-04 14:25:04 +02:00
parent e24f26c28f
commit f1ec0af507
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
3 changed files with 17 additions and 9 deletions

View file

@ -1,15 +1,18 @@
use crate::system;
use iced_futures::MaybeSend;
use std::fmt;
/// An operation to be performed on the system.
pub enum Action<T> {
/// Query system information and produce `T` with the result.
QueryInformation(Box<dyn Fn(system::Information) -> T>),
QueryInformation(Box<dyn Closure<T>>),
}
pub trait Closure<T>: Fn(system::Information) -> T + MaybeSend {}
impl<T, O> Closure<O> for T where T: Fn(system::Information) -> O + MaybeSend {}
impl<T> Action<T> {
/// Maps the output of a system [`Action`] using the provided closure.
pub fn map<A>(