pub struct ThreadPoolBuilder { /* private fields */ }
Expand description
Build a ThreadPool
Modify default thread pool parameters and build the thread pool
Implementations§
source§impl ThreadPoolBuilder
impl ThreadPoolBuilder
sourcepub fn new() -> ThreadPoolBuilder
pub fn new() -> ThreadPoolBuilder
Create a new builder
Default values:
name
- “unnamed”tasks
- 1queue_size
- 16join_error_handler
- a simple panicking error handlershutdown_mode
- ShutdownMode::Immediate
Example
use command_executor::shutdown_mode::ShutdownMode;
use command_executor::thread_pool::ThreadPool;
use command_executor::thread_pool_builder::ThreadPoolBuilder;
fn create_thread_pool() -> Result<ThreadPool, anyhow::Error> {
ThreadPoolBuilder::new()
.name_str("example")
.tasks(4)
.queue_size(16)
.shutdown_mode(ShutdownMode::CompletePending)
.build()
}
sourcepub fn name(&mut self, name: String) -> &mut ThreadPoolBuilder
pub fn name(&mut self, name: String) -> &mut ThreadPoolBuilder
Set the base name for threads in the thread pool
sourcepub fn name_str(&mut self, name: &str) -> &mut ThreadPoolBuilder
pub fn name_str(&mut self, name: &str) -> &mut ThreadPoolBuilder
Set the base name for threads in the thread pool. A convenience method that accepts &str
sourcepub fn tasks(&mut self, tasks: usize) -> &mut ThreadPoolBuilder
pub fn tasks(&mut self, tasks: usize) -> &mut ThreadPoolBuilder
Set the number of threads in the thread pool
sourcepub fn shutdown_mode(
&mut self,
shutdown_mode: ShutdownMode
) -> &mut ThreadPoolBuilder
pub fn shutdown_mode( &mut self, shutdown_mode: ShutdownMode ) -> &mut ThreadPoolBuilder
Specify the ShutdownMode
sourcepub fn queue_size(&mut self, queue_size: usize) -> &mut ThreadPoolBuilder
pub fn queue_size(&mut self, queue_size: usize) -> &mut ThreadPoolBuilder
Specify the queue size for the thread pool
sourcepub fn join_error_handler(
&mut self,
join_error_handler: fn(_: String, _: String)
) -> &mut ThreadPoolBuilder
pub fn join_error_handler( &mut self, join_error_handler: fn(_: String, _: String) ) -> &mut ThreadPoolBuilder
Set the error handler that is called for each thread that exited with error during join
sourcepub fn build(&self) -> Result<ThreadPool, Error>
pub fn build(&self) -> Result<ThreadPool, Error>
Build the thread pool
Auto Trait Implementations§
impl RefUnwindSafe for ThreadPoolBuilder
impl Send for ThreadPoolBuilder
impl Sync for ThreadPoolBuilder
impl Unpin for ThreadPoolBuilder
impl UnwindSafe for ThreadPoolBuilder
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