Crates.io | task_pool |
lib.rs | task_pool |
version | |
source | src |
created_at | 2023-07-28 13:23:59.553572+00 |
updated_at | 2025-02-17 03:23:12.838802+00 |
description | Flexible abstraction for task-based composable multithreading. |
homepage | |
repository | https://github.com/DouglasDwyer/task_pool |
max_upload_size | |
id | 928518 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
task_pool
offers a flexible abstraction for composing and distributing work within a fixed hardware threadpool. To that end, it offers the following features:
To use task_pool
, there are three steps:
WorkProvider
instances (such as a queue or chain of multiple queues)TaskPool
which consumes those instancesWorkProvider
s which are handled by the threadpoolThe following example shows these steps in action:
// 1. Create a queue from which we can spawn tasks
let queue = TaskQueue::<Fifo>::default();
// 2. Create a threadpool that draws from the provided queue. Forget the threadpool so that it runs indefinitely.
TaskPool::new(queue.clone(), 4).forget();
// 3. Spawn a task into the queue and synchronously await its completion.
assert_eq!(queue.spawn(once(|| { println!("This will execute on background thread."); 2 })).join(), 2);
// ...or, asynchronously await its completion.
assert_eq!(queue.spawn(once(|| { println!("This will execute on background thread."); 2 })).await, 2);