pub struct TaskPool { /* private fields */ }Expand description
A fixed-size pool of worker threads driving an unbounded set of suspended tasks.
Implementations§
Source§impl TaskPool
impl TaskPool
Sourcepub fn new(n_workers: usize) -> Self
pub fn new(n_workers: usize) -> Self
Build a pool with n_workers threads (clamped to at least 1).
Sourcepub fn worker_count(&self) -> usize
pub fn worker_count(&self) -> usize
Number of worker threads in the pool.
Sourcepub fn spawn(&self, future: impl Future<Output = ()> + Send + 'static)
pub fn spawn(&self, future: impl Future<Output = ()> + Send + 'static)
Spawn a future. It runs to completion on the pool, suspending (off-thread) whenever it awaits, with no thread dedicated to it.
Sourcepub fn shutdown(self)
pub fn shutdown(self)
Stop the workers once the current ready queue drains. Joins all threads. Call after the work you spawned has completed.
The flag is set while holding the queue lock, which is what makes a worker’s check-then-park atomic against it: a worker between the two holds that lock, so this store waits for it to park before the notify goes out.
Auto Trait Implementations§
impl !RefUnwindSafe for TaskPool
impl !UnwindSafe for TaskPool
impl Freeze for TaskPool
impl Send for TaskPool
impl Sync for TaskPool
impl Unpin for TaskPool
impl UnsafeUnpin for TaskPool
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