pub struct Task<Msg> { /* private fields */ }Expand description
Work to run in the background with progress, cancellation and an outcome.
use std::time::Duration;
use qframe::runtime::{Command, Task, TaskEvent};
enum Msg {
Task(TaskEvent),
Built(String),
}
let task = Task::new("Build image", |cx| {
for step in 0..4 {
if !cx.sleep(Duration::from_millis(300)) {
return Err("stopped".into());
}
cx.progress((step + 1) as f32 / 4.0);
}
Ok(Msg::Built("sha256:4f2a".into()))
})
.on_event(Msg::Task);
let id = task.id(); // keep it to cancel the task later
let command: Command<Msg> = Command::task(task);Implementations§
Source§impl<Msg: Send + 'static> Task<Msg>
impl<Msg: Send + 'static> Task<Msg>
Sourcepub fn new(
label: impl Into<String>,
work: impl FnOnce(&TaskCx<Msg>) -> Result<Msg, String> + Send + 'static,
) -> Self
pub fn new( label: impl Into<String>, work: impl FnOnce(&TaskCx<Msg>) -> Result<Msg, String> + Send + 'static, ) -> Self
A task labelled label running work. Ok delivers its message; Err fails the task
with a reason.
Auto Trait Implementations§
impl<Msg> !RefUnwindSafe for Task<Msg>
impl<Msg> !Sync for Task<Msg>
impl<Msg> !UnwindSafe for Task<Msg>
impl<Msg> Freeze for Task<Msg>
impl<Msg> Send for Task<Msg>
impl<Msg> Unpin for Task<Msg>
impl<Msg> UnsafeUnpin for Task<Msg>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more