pub trait Strategy: Debug {
// Required methods
fn submit(&self, task: Box<dyn Task>) -> Result;
fn num_workers(&self) -> usize;
fn num_tasks_running(&self) -> usize;
fn num_tasks_pending(&self) -> usize;
fn capacity(&self) -> usize;
}Expand description
Execution strategy.
Besides task submission, strategies must also allow to inspect the number of
workers, as well as the number of running and pending tasks, which might be
useful for implementing more fine-grained execution strategies. It’s also
used to determine whether an Executor is idle or at capacity.
Required Methods§
Sourcefn submit(&self, task: Box<dyn Task>) -> Result
fn submit(&self, task: Box<dyn Task>) -> Result
Submits a task.
This method submits a Task, which should be executed by one of the
worker threads as soon as possible. How and when the task is executed,
and in what order tasks are executed, is entirely up to the strategy
implementation.
§Errors
This method should return an error when a problem is encountered trying to submit the given task, but not within the task itself.
Sourcefn num_workers(&self) -> usize
fn num_workers(&self) -> usize
Returns the number of workers.
Sourcefn num_tasks_running(&self) -> usize
fn num_tasks_running(&self) -> usize
Returns the number of running tasks.
Sourcefn num_tasks_pending(&self) -> usize
fn num_tasks_pending(&self) -> usize
Returns the number of pending tasks.