pub struct ThreadPool<P>where
P: PoolItem,{ /* private fields */ }
Expand description
This struct represents a pool of threads that can target a particular type of
resource (a resource being a struct that implements PoolItem
)
In order to allow for distribution over multiple threads each resource must have an id that allows for routing to a particular thread.
Implementations§
Source§impl<P> ThreadPool<P>where
P: PoolItem + 'static,
impl<P> ThreadPool<P>where
P: PoolItem + 'static,
Sourcepub fn new(thread_pool_size: u64) -> Self
pub fn new(thread_pool_size: u64) -> Self
This function creates a new ThreadPool
Internally it creates a collection of threads. It has the ability to communicate with the threads via a vec of channels (there is one channel for each spawned thread)
The number of threads is determined by the passed in thread_pool_size
Source§impl<P> ThreadPool<P>where
P: PoolItem,
impl<P> ThreadPool<P>where
P: PoolItem,
Sourcepub fn send_and_receive<T>(
&self,
requests: impl Iterator<Item = T>,
) -> Result<impl Iterator<Item = T::Response>, SendError<SenderCouplet<P>>>where
T: RequestWithResponse<P> + IdTargeted,
pub fn send_and_receive<T>(
&self,
requests: impl Iterator<Item = T>,
) -> Result<impl Iterator<Item = T::Response>, SendError<SenderCouplet<P>>>where
T: RequestWithResponse<P> + IdTargeted,
This function sends a request to a worker thread and receives a response back
The request is received as a vec and the responses are received back in a vec
pub fn send_and_receive_once<T>(
&self,
request: T,
) -> Result<T::Response, SendError<SenderCouplet<P>>>where
T: RequestWithResponse<P> + IdTargeted,
Source§impl<P> ThreadPool<P>where
P: PoolItem,
impl<P> ThreadPool<P>where
P: PoolItem,
Sourcepub fn shutdown(&self) -> Vec<ThreadShutdownResponse>
pub fn shutdown(&self) -> Vec<ThreadShutdownResponse>
This function requests that the thread pool shutdowns It sends the shutdown message to each of it’s contained PoolThreads The sending of this message should cause the message loop to exit and the thread to end
Source§impl<P> ThreadPool<P>where
P: PoolItem,
impl<P> ThreadPool<P>where
P: PoolItem,
Sourcepub fn thread_count(&self) -> usize
pub fn thread_count(&self) -> usize
This function returns the number of threads in the thread pool
Trait Implementations§
Source§impl<P> Debug for ThreadPool<P>
impl<P> Debug for ThreadPool<P>
Source§impl<P> Drop for ThreadPool<P>where
P: PoolItem,
impl<P> Drop for ThreadPool<P>where
P: PoolItem,
Source§impl<P> SenderAndReceiver<P> for ThreadPool<P>where
P: PoolItem,
An implementation of the [ThreadPoolSenderAndReceiver
] trait for ThreadPool
impl<P> SenderAndReceiver<P> for ThreadPool<P>where
P: PoolItem,
An implementation of the [ThreadPoolSenderAndReceiver
] trait for ThreadPool