Rust Threadpool Executor
A simple thread pool for running jobs on the worker threads. You can specify the core workers which will live as long as the thread pool , maximum workers which will live with a given keep alive time, and the policy when the jobs submited exceed the maximum size of the workers.
Usage
Create a fix size thread pool and when the job submited will wait when all workers are busy:
let pool = new;
let mut expectation = pool.execute.unwrap;
assert_eq!;
You can handle wait the result for a specifid time:
let pool = new;
let r = pool.execute;
let res = r.unwrap.get_result_timeout;
assert!;
if let Err = res
Use Builder
to create a thread pool:
let pool = new
.core_pool_size
.maximum_pool_size
.keep_alive_time
.exeed_limit_policy
.build;
The workers runs in this thread pool will try to catch the Panic!
using the std::panic::catch_unwind
in the functions you submit, if catched, the get_result
method will give you a Panic
kind ExecutorError.
let pool = new;
let r = pool.execute;
let res = r.unwrap.get_result;
assert!;
if let Err = res
You can cancel the task when it's waiting in line. The task cannot be cancelled when it's started running.
let pool = new;
pool.execute.unwrap;
let mut exp = pool.execute.unwrap;
exp.cancel;