Struct messaging_thread_pool::ThreadPool
source · pub struct ThreadPool<E>where
E: Element,{ /* 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 Element)
In order to allow for distribution over multiple threads each resource must have an id that allows for routing to a particular thread.
It is necessary when request are made
Implementations
sourceimpl<E> ThreadPool<E>where
E: Element + 'static,
impl<E> ThreadPool<E>where
E: Element + 'static,
sourcepub fn new(thread_pool_size: usize) -> Self
pub fn new(thread_pool_size: usize) -> 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
sourceimpl<E> ThreadPool<E>where
E: Element,
impl<E> ThreadPool<E>where
E: Element,
sourcepub fn send_and_receive<T, U>(&self, requests: &RefCell<Vec<T>>) -> Vec<U>where
T: Into<ThreadRequest<E::Request>> + IdTargeted,
U: From<ThreadResponse<E::Response>> + IdTargeted,
pub fn send_and_receive<T, U>(&self, requests: &RefCell<Vec<T>>) -> Vec<U>where
T: Into<ThreadRequest<E::Request>> + IdTargeted,
U: From<ThreadResponse<E::Response>> + 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
sourceimpl<E> ThreadPool<E>where
E: Element,
impl<E> ThreadPool<E>where
E: Element,
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
sourceimpl<E> ThreadPool<E>where
E: Element,
impl<E> ThreadPool<E>where
E: Element,
sourcepub fn thread_count(&self) -> NonZeroUsize
pub fn thread_count(&self) -> NonZeroUsize
This function returns the number of threads in the thread pool