pub struct WorkerPool<Up, Down> where
    Up: Send + 'static,
    Down: Send + 'static, 
{ /* private fields */ }
Expand description

The main struct, represents a pool of worker. The owner of this struct is the “Manager”, while the threads handled by this struct are the “Workers”.

Example:

use worker_pool::WorkerPool;

let mut pool: WorkerPool<String, ()> = WorkerPool::new(100);

pool.execute(|tx, _rx| {
    tx.send(String::from("Hello"));
    tx.send(String::from("world!"));
});

assert_eq!(pool.stop().collect::<Vec<_>>().join(" "), "Hello world!");

Implementations

Returns the maximum length of the message queue

Receives a single message from a worker; blocking. If you need to call this function repeatedly, then consider iterating over the result of recv_burst instead.

Returns an iterator that will yield a “burst” of messages. This iterator will respect causality, meaning that it will not yield any message that were sent after it was created. You can thus safely iterate over all of the elements of this iterator without risking a livelock.

Stops the execution of all threads, returning an iterator that will yield and join all of the messages from the workers. As soon as this function returns, the WorkerPool will be back to its starting state, allowing you to execute more tasks immediately.

The returned iterator will read all of the remaining messages one by one. Once the last message is received, it will join all threads.

Stops the execution of all threads and joins them. Returns a Vec containing all of the remaining yielded values. Note that the returned Vec will ignore the buffer_length limitation.

Sends msg to every worker

Sends msg to a single worker, in a round-robin fashion. Returns Err if there is no worker or if the worker has dropped its receiver.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.