pub trait Task:
Send
+ UnwindSafe
+ 'static {
// Required method
fn execute(self: Box<Self>) -> Tasks;
}Expand description
Task.
Tasks are units of work that can be submitted to an Executor, which
forwards them for execution to an execution Strategy that is set when
creating the Executor. Moreover, tasks can create and return further
Tasks, which are handled by the same execution strategy, allowing for
immediate or deferred execution, as implemented by the strategy. If a task
panics, it doesn’t take the worker thread or executor with it.
Note that tasks will almost always need to capture environment variables,
which is why they’re created from FnOnce and must be Send.
Required Methods§
Sourcefn execute(self: Box<Self>) -> Tasks
fn execute(self: Box<Self>) -> Tasks
Executes the task.
This methods executes the task, and may return further tasks as part of a task collection, which are executed by the same execution strategy. As task execution must be infallible, tasks might use channels in order to communicate results or errors back to the main thread.
Trait Implementations§
Source§impl<T> From<T> for Box<dyn Task>where
T: Task,
impl<T> From<T> for Box<dyn Task>where
T: Task,
Source§fn from(task: T) -> Self
fn from(task: T) -> Self
Creates a boxed task from a task.
This implementation ensures we can comfortably pass bare closures, as
well as boxed tasks to Executor::submit, which allows to resubmit
tasks that were returned as part of Error::Submit due to capacity
limits of the execution strategy.