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 Freeze for Builder
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