Struct pawawwewism::WorkerSet

source ·
pub struct WorkerSet<I: Send + 'static> { /* private fields */ }
Expand description

An owned set of Worker threads that all process the same type of message.

This can be used to spread identical computations across several threads, when a single thread does not provide enough throughput for the application.

When WorkerSet::send is called, or the WorkerSet is dropped, panics from the worker threads are propagated to the owning thread. If more than one worker thread has panicked, the panic payload of one of the panicked threads will be propagated.

Implementations§

source§

impl WorkerSet<()>

source

pub fn builder() -> WorkerSetBuilder

Returns a builder that can be used to configure and spawn a WorkerSet.

source§

impl<I: Send + 'static> WorkerSet<I>

source

pub fn send(&mut self, msg: I)

Sends a message to one of the worker threads in this set.

If no worker is available to process the message, this will block until one is available.

If the worker has panicked, this will propagate the panic to the calling thread.

source

pub fn try_send(&mut self, msg: I) -> Result<(), I>

Tries to send a message to one of the worker threads, without blocking.

If no thread is available to accept the message, this method will return Err instead of blocking. Otherwise, the behavior is the same as for WorkerSet::send.

Note that this operation may fail for a short time after the user-provided processing closure has finished execution. This can happen because the worker threads may perform internal coordination before they are considered available for the try_send operation again.

Trait Implementations§

source§

impl<I: Send + 'static> Drop for WorkerSet<I>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<I> !RefUnwindSafe for WorkerSet<I>

§

impl<I> Send for WorkerSet<I>

§

impl<I> Sync for WorkerSet<I>

§

impl<I> Unpin for WorkerSet<I>

§

impl<I> !UnwindSafe for WorkerSet<I>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.