pub struct Builder { /* private fields */ }Expand description
Thread pool configuration.
Provide detailed control over the properties and behavior of the thread pool.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn core_pool_size(self, val: usize) -> Self
pub fn core_pool_size(self, val: usize) -> Self
Set the thread pool’s core size.
The number of threads to keep in the pool, even if they are idle.
Sourcepub fn max_pool_size(self, val: usize) -> Self
pub fn max_pool_size(self, val: usize) -> Self
Set the thread pool’s maximum size
The maximum number of threads to allow in the pool.
Sourcepub fn keep_alive(self, val: Duration) -> Self
pub fn keep_alive(self, val: Duration) -> Self
Set the thread keep alive duration
When the number of threads is greater than core target or core threads are allowed to timeout, this is the maximum time that idle threads will wait for new tasks before terminating.
Sourcepub fn allow_core_thread_timeout(self) -> Self
pub fn allow_core_thread_timeout(self) -> Self
Allow core threads to timeout
Sourcepub fn work_queue_capacity(self, val: usize) -> Self
pub fn work_queue_capacity(self, val: usize) -> Self
Maximum number of jobs that can be pending in the work queue
Sourcepub fn name_prefix<S: Into<String>>(self, val: S) -> Self
pub fn name_prefix<S: Into<String>>(self, val: S) -> Self
Set name prefix of threads spawned by the pool
Thread name prefix is used for generating thread names. For example, if
prefix is my-pool-, then threads in the pool will get names like
my-pool-1 etc.
Sourcepub fn stack_size(self, val: usize) -> Self
pub fn stack_size(self, val: usize) -> Self
Set the stack size of threads spawned by the pool
Sourcepub fn after_start<F>(self, f: F) -> Self
pub fn after_start<F>(self, f: F) -> Self
Execute function f right after each thread is started but before
running any tasks on it
This is initially intended for bookkeeping and monitoring uses
Sourcepub fn before_stop<F>(self, f: F) -> Self
pub fn before_stop<F>(self, f: F) -> Self
Execute function f before each worker thread stops
This is initially intended for bookkeeping and monitoring uses
Sourcepub fn build<T: Task>(self) -> (Sender<T>, ThreadPool<T>)
pub fn build<T: Task>(self) -> (Sender<T>, ThreadPool<T>)
Build and return the configured thread pool