task_pool
task_pool offers a flexible abstraction for composing and distributing work within a fixed hardware threadpool. To that end, it offers the following features:
- The ability to define and compose sources of work
- The ability to create hardware threadpool and consume those sources
- A variety of high-level abstractions for scheduling, such as awaitable tasks
Usage
To use task_pool, there are three steps:
- Creating and initializing
WorkProviderinstances (such as a queue or chain of multiple queues) - Creating a hardware
TaskPoolwhich consumes those instances - Spawning high-level tasks on the
WorkProviders which are handled by the threadpool
The following example shows these steps in action:
// 1. Create a queue from which we can spawn tasks
let queue = default;
// 2. Create a threadpool that draws from the provided queue. Forget the threadpool so that it runs indefinitely.
new.forget;
// 3. Spawn a task into the queue and synchronously await its completion.
assert_eq!;
// ...or, asynchronously await its completion.
assert_eq!;