Expand description
A small, fixed-size worker pool for offloading CPU-bound work off the main thread — mip/image processing, physics steps, any one-off or recurring task that shouldn’t block a frame.
Deliberately NOT a full async runtime: no cancellation, no priorities, no work-stealing. Just a bounded number of OS threads pulling jobs off one shared, lock-free MPMC queue, with results delivered back via a channel you poll from an ordinary system. If you outgrow this — need cancellation, need priority scheduling — that’s real, separate infrastructure to build once you have a concrete case for it, not something to guess at now.
Requires the crossbeam-channel crate (lock-free MPMC), since
std::sync::mpsc only supports a single consumer and would otherwise
force a Mutex around the receiver for multiple worker threads.
Structs§
- Background
Tasks - The worker pool itself. Insert as a resource once, at startup; every
system that needs to offload work reaches for
Res<BackgroundTasks>and callsspawn. - Background
Tasks Plugin - Registers
BackgroundTasksas a resource with the given worker count. - Task
Handle - A handle to a single in-flight (or already-finished) task. Poll it
from an ordinary system with
try_recv— never blocks.