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()
.with_name_str("example")
.with_tasks(4)
.with_queue_size(16)
.with_shutdown_mode(ShutdownMode::CompletePending)
.build()
}
Sourcepub fn with_name(&mut self, name: String) -> &mut ThreadPoolBuilder
pub fn with_name(&mut self, name: String) -> &mut ThreadPoolBuilder
Set the base name for threads in the thread pool
Sourcepub fn with_name_str(&mut self, name: &str) -> &mut ThreadPoolBuilder
pub fn with_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 with_tasks(&mut self, tasks: usize) -> &mut ThreadPoolBuilder
pub fn with_tasks(&mut self, tasks: usize) -> &mut ThreadPoolBuilder
Set the number of threads in the thread pool
Sourcepub fn with_shutdown_mode(
&mut self,
shutdown_mode: ShutdownMode,
) -> &mut ThreadPoolBuilder
pub fn with_shutdown_mode( &mut self, shutdown_mode: ShutdownMode, ) -> &mut ThreadPoolBuilder
Specify the ShutdownMode
Sourcepub fn with_queue_type(
&mut self,
queue_type: QueueType,
) -> &mut ThreadPoolBuilder
pub fn with_queue_type( &mut self, queue_type: QueueType, ) -> &mut ThreadPoolBuilder
Specify the QueueType
Sourcepub fn with_queue_size(&mut self, queue_size: usize) -> &mut ThreadPoolBuilder
pub fn with_queue_size(&mut self, queue_size: usize) -> &mut ThreadPoolBuilder
Specify the queue size for the thread pool
Sourcepub fn with_join_error_handler(
&mut self,
join_error_handler: fn(String, String),
) -> &mut ThreadPoolBuilder
pub fn with_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
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ThreadPoolBuilder
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