pub struct MultiThreadedExecutor { /* private fields */ }
Implementations§
Source§impl MultiThreadedExecutor
impl MultiThreadedExecutor
Sourcepub fn new_single() -> MultiThreadedExecutor
pub fn new_single() -> MultiThreadedExecutor
Creates a new MultiThreadedExecutor
that has just a single worker.
Sourcepub fn new_fixed(worker_count: usize) -> MultiThreadedExecutor
pub fn new_fixed(worker_count: usize) -> MultiThreadedExecutor
Creates a new MultiThreadedExecutor
with a fixed number of workers pre-allocated to it,
and cannot automatically grow to add new workers.
Note: Workers can be added or removed after-the-fact with the appropriate functions.
Sourcepub fn submit<T: Send + 'static, F: Future<Output = T> + Send + 'static>(
&mut self,
fut: F,
) -> Result<TaskHandle<T>, TaskError>
pub fn submit<T: Send + 'static, F: Future<Output = T> + Send + 'static>( &mut self, fut: F, ) -> Result<TaskHandle<T>, TaskError>
Submits a new task to be run on this executor. The task will start to be run as soon as the executor has available capacity to run it.
If there is no available worker, and additional workers are permitted to be added, a new worker will be allocated and started to service the task, and will be cached for future use.
If no available worker and no additional workers are permitted, this will block until a worker accepts the task. It will NOT be queued. Once accepted, it will be immediately executed.
This function returns a TaskHandle
that can be used to retrieve any return
result from the operation itself.
Sourcepub fn add_worker(&mut self) -> Result<(), Error>
pub fn add_worker(&mut self) -> Result<(), Error>
Manually adds an additional worker to this Executor. This WILL spawn and start a new thread and will immediately start accepting tasks.
This function will return an error type if the operating system does not permit a new thread to be spawned for the worker.
Sourcepub fn remove_worker(&mut self)
pub fn remove_worker(&mut self)
Manually removes a worker from the Executor. Tries to find a worker that isn’t doing anything first and remove that. If everyone’s busy, just removes and blocks the front, the oldest worker.