pub struct BackgroundTasks { /* private fields */ }Expand description
The worker pool itself. Insert as a resource once, at startup; every
system that needs to offload work reaches for Res<BackgroundTasks>
and calls spawn.
Implementations§
Source§impl BackgroundTasks
impl BackgroundTasks
Sourcepub fn new(worker_count: usize) -> Self
pub fn new(worker_count: usize) -> Self
Spawns worker_count OS threads, each pulling jobs off one shared,
lock-free queue until the pool itself is dropped. A worker count
around your CPU’s core count (minus one, to leave room for the
main thread) is a reasonable default; tune based on actual
measured load.
Sourcepub fn spawn<T: Send + 'static>(
&self,
work: impl FnOnce() -> T + Send + 'static,
) -> TaskHandle<T>
pub fn spawn<T: Send + 'static>( &self, work: impl FnOnce() -> T + Send + 'static, ) -> TaskHandle<T>
Queue work to run on the pool. Returns a TaskHandle you can
poll (non-blocking) from any system to check whether it’s done.
work runs on whichever worker thread picks it up next — don’t
assume anything about timing or ordering relative to other spawned
tasks unless you build that coordination yourself.
Auto Trait Implementations§
impl Freeze for BackgroundTasks
impl RefUnwindSafe for BackgroundTasks
impl Send for BackgroundTasks
impl Sync for BackgroundTasks
impl Unpin for BackgroundTasks
impl UnsafeUnpin for BackgroundTasks
impl UnwindSafe for BackgroundTasks
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more