Struct threadpool_executor::threadpool::Builder
source · pub struct Builder { /* private fields */ }Implementations§
source§impl Builder
impl Builder
sourcepub fn new() -> Builder
pub fn new() -> Builder
A builder use to build a ThreadPool
Example
let pool = threadpool_executor::threadpool::Builder::new()
.core_pool_size(1)
.maximum_pool_size(3)
.keep_alive_time(std::time::Duration::from_secs(300)) // None-core-thread keep_alive_time, default value is 5 minutes.
.exeed_limit_policy(threadpool_executor::threadpool::ExceedLimitPolicy::Reject) // Default value is Wait.
.build();sourcepub fn core_pool_size(self, size: usize) -> Builder
pub fn core_pool_size(self, size: usize) -> Builder
Core threads will run until the threadpool dropped.
Example
let pool = threadpool_executor::threadpool::Builder::new()
.core_pool_size(1)
.build();sourcepub fn maximum_pool_size(self, size: usize) -> Builder
pub fn maximum_pool_size(self, size: usize) -> Builder
Maximum threads that run in this threadpool, include the core threads,
the size of the none-core threads = maximum_pool_size - core_pool_size.
None core threads will live with a given keep_alive_time. If the keep_alive_time
is not set, it will default to 5 minutes.
Example
let pool = threadpool_executor::threadpool::Builder::new()
.core_pool_size(1)
.maximum_pool_size(3)
.build();sourcepub fn exeed_limit_policy(self, policy: ExceedLimitPolicy) -> Builder
pub fn exeed_limit_policy(self, policy: ExceedLimitPolicy) -> Builder
When the threads are all working, the new tasks coming will follow the given policy
Example
let pool = threadpool_executor::threadpool::Builder::new()
.core_pool_size(1)
.maximum_pool_size(1)
.exeed_limit_policy(threadpool_executor::threadpool::ExceedLimitPolicy::Reject)
.build();
let res = pool.execute(|| {
std::thread::sleep(std::time::Duration::from_secs(3));
});
assert!(res.is_ok());
let res = pool.execute(|| "a");
assert!(res.is_err());
if let Err(err) = res {
matches!(err.kind(), threadpool_executor::error::ErrorKind::TaskRejected);
}sourcepub fn keep_alive_time(self, keep_alive_time: Duration) -> Builder
pub fn keep_alive_time(self, keep_alive_time: Duration) -> Builder
None core threads will live with a given keep_alive_time. If the keep_alive_time
is not set, it will default to 5 minutes.
Example
let pool = threadpool_executor::threadpool::Builder::new()
.core_pool_size(1)
.maximum_pool_size(3)
.keep_alive_time(std::time::Duration::from_secs(60))
.build();pub fn build(self) -> ThreadPool
Auto Trait Implementations§
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
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