pub struct Task {
pub after_completion_timer: Option<Timer>,
/* private fields */
}
Expand description
A Task
is a seperate thread that is owned by the framework.
In difference to a Thread
, you don’t have to await()
the result of a Task
,
you can just hand the task to the framework (via AppResources::add_task
) and
the framework will automatically update the UI when the task is finished.
This is useful to offload actions such as loading long files, etc. to a background thread.
Azul will join the thread automatically after it is finished (joining won’t block the UI).
Fields§
§after_completion_timer: Option<Timer>
Timer that will run directly after this task is completed.
Implementations§
Source§impl Task
impl Task
Sourcepub fn new<U: Send + 'static>(
data: Arc<Mutex<U>>,
callback: TaskCallback<U>,
) -> Self
pub fn new<U: Send + 'static>( data: Arc<Mutex<U>>, callback: TaskCallback<U>, ) -> Self
Creates a new task from a callback and a set of input data - which has to be wrapped in an Arc<Mutex<T>>>
.
Sourcepub fn then(self, timer: Timer) -> Self
pub fn then(self, timer: Timer) -> Self
Stores a Timer
that will run after the task has finished.
Often necessary to “clean up” or copy data from the background task into the UI.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns true if the task has been finished, false otherwise