[−][src]Crate actix_dynamic_threadpool
Dynamic thread pool for blocking operations
The pool would lazily generate thread according to the workload and spawn up to a total amount
of you machine's logical CPU cores * 5
threads. Any spawned threads kept idle for 30 seconds
would be recycled and de spawned.
*. Settings are configuable through env variables.
Example:
use std::env::set_var; #[actix_rt::main] async fn main() { // Optional: Set the max thread count for the blocking pool. set_var("ACTIX_THREADPOOL", "30"); // Optional: Set the min thread count for the blocking pool. set_var("ACTIX_THREADPOOL_MIN", "1"); // Optional: Set the timeout duration IN SECONDS for the blocking pool's idle threads. set_var("ACTIX_THREADPOOL_TIMEOUT", "30"); let future = actix_dynamic_threadpool::run(|| { /* Some blocking code with a Result<T, E> as return type */ Ok::<usize, ()>(1usize) }); /* We can await on this blocking code and NOT block our runtime. When we waiting our actix runtime can switch to other async tasks. */ let result: Result<usize, actix_dynamic_threadpool::BlockingError<()>> = future.await; assert_eq!(1usize, result.unwrap()) }
Structs
CpuFuture | Blocking operation completion future. It resolves with results of blocking function execution. |
Enums
BlockingError | Blocking operation execution error |
Functions
run | Execute blocking function on a thread pool, returns future that resolves to result of the function execution. |