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<()>
impl WorkerSet<()>
sourcepub fn builder() -> WorkerSetBuilder
pub fn builder() -> WorkerSetBuilder
Returns a builder that can be used to configure and spawn a WorkerSet
.
source§impl<I: Send + 'static> WorkerSet<I>
impl<I: Send + 'static> WorkerSet<I>
sourcepub fn send(&mut self, msg: I)
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.
sourcepub fn try_send(&mut self, msg: I) -> Result<(), I>
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.