pub struct ThreadPool {
pub workers: Vec<Worker>,
pub sender: Sender<Box<dyn FnOnce() + Send + 'static>>,
}
Expand description
The ThreadPool data structure holds the underlying mechanism for processing concurrent requests. It has a sender which propagates requests through the channel and a vector of workers.
Fields§
§workers: Vec<Worker>
This is an array of workers which constantly listen for requests to the server.
The number of workers defaults to 10 but can be provided with the threads
option.
sender: Sender<Box<dyn FnOnce() + Send + 'static>>
This is a sender type used to propagate requests through a channel that every worker listens on.
Implementations§
Source§impl ThreadPool
impl ThreadPool
Sourcepub fn new(pool_size: usize) -> ThreadPool
pub fn new(pool_size: usize) -> ThreadPool
Returns a struct with the type ThreaPool. This method is used to initiate a new threadpool when the server is started. The workers/threads share ownership of a reciever which is used to accept requests.
Args
pool_size
- This represents the number of workers/threads the server is started with.
§Examples
use server::thread::ThreadPool;
let pool: ThreadPool = ThreadPool::new(5);
assert_eq!(pool.workers.len(), 5);
§Panics
The associated function panics when the pool size provided is less that 1 or greater than 100.
Auto Trait Implementations§
impl Freeze for ThreadPool
impl !RefUnwindSafe for ThreadPool
impl Send for ThreadPool
impl Sync for ThreadPool
impl Unpin for ThreadPool
impl !UnwindSafe for ThreadPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more