Struct MultiThreadedExecutor

Source
pub struct MultiThreadedExecutor { /* private fields */ }

Implementations§

Source§

impl MultiThreadedExecutor

Source

pub fn new_single() -> MultiThreadedExecutor

Creates a new MultiThreadedExecutor that has just a single worker.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn shutdown(&self)

Trait Implementations§

Source§

impl Default for MultiThreadedExecutor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for MultiThreadedExecutor

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.