pub struct TaskControl<T, S> { /* private fields */ }
Expand description
A task wrapper that runs the task asynchronously and provides access to its state.
Implementations§
Source§impl<T: AsyncRun<S>, S: 'static + Send> TaskControl<T, S>
impl<T: AsyncRun<S>, S: 'static + Send> TaskControl<T, S>
Sourcepub fn new(task: T) -> Self
pub fn new(task: T) -> Self
Creates the task control, taking the state for the task but not yet creating or starting it.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true if a task is running.
Sourcepub fn state(&self) -> Option<&S>
pub fn state(&self) -> Option<&S>
Gets the transient task state.
Panics if the task is running.
Sourcepub fn state_mut(&mut self) -> Option<&mut S>
pub fn state_mut(&mut self) -> Option<&mut S>
Gets the transient task state.
Panics if the task is running.
Sourcepub fn get(&self) -> (&T, Option<&S>)
pub fn get(&self) -> (&T, Option<&S>)
Gets the task and its state.
Panics if the task is running.
Sourcepub fn get_mut(&mut self) -> (&mut T, Option<&mut S>)
pub fn get_mut(&mut self) -> (&mut T, Option<&mut S>)
Gets the state and the task.
Panics if the task is running.
Sourcepub fn into_inner(self) -> (T, Option<S>)
pub fn into_inner(self) -> (T, Option<S>)
Retrieves the task and its state.
Panics if the task is running.
Sourcepub fn update_with(
&mut self,
f: impl 'static + Send + FnOnce(&mut T, Option<&mut S>),
)
pub fn update_with( &mut self, f: impl 'static + Send + FnOnce(&mut T, Option<&mut S>), )
Calls f
against the task and its state.
If the task is running, then f
will run remotely and will not
necessarily finish before this routine returns.
Sourcepub fn insert(
&mut self,
spawn: impl Spawn,
name: impl Into<Arc<str>>,
state: S,
) -> &mut S
pub fn insert( &mut self, spawn: impl Spawn, name: impl Into<Arc<str>>, state: S, ) -> &mut S
Inserts the state the task object will use to run and starts the backing task, but does not start running it.
Sourcepub fn start(&mut self) -> bool
pub fn start(&mut self) -> bool
Starts the task if it is not already running.
Returns true if the task is now running (even if it was previously running). Returns false if the task is not running (either because its state has not been inserted, or because it has already completed).