pub struct Pool { /* private fields */ }Expand description
Runs background work on worker threads, or, without threads, on the
thread that runs it. Cheap to clone: clones share the pool. A worker
starts when a task arrives while every running worker is busy, up to the
pool’s thread count, so a pool that runs nothing starts no threads. Its
threads end once the last clone and the last TaskGroup of it drop, or
once it’s shut_down, dropping the tasks still
queued.
Implementations§
Source§impl Pool
impl Pool
Sourcepub fn new(threads: usize) -> Pool
pub fn new(threads: usize) -> Pool
A pool of up to threads worker threads, which start as tasks
arrive.
Sourcepub fn local() -> Pool
pub fn local() -> Pool
A pool without threads, whose tasks run when run_until
runs them, on one thread.
Sourcepub fn spawn(&self, task: impl FnOnce() + Send + 'static)
pub fn spawn(&self, task: impl FnOnce() + Send + 'static)
Runs task on the pool, in its own lane.
Sourcepub fn shut_down(&self)
pub fn shut_down(&self)
Stops the pool now, whatever clones and groups of it are left, as when the last of them drops: its workers end once their current tasks return, the tasks waiting for a worker drop, and tasks spawned later drop at once. For an owner whose work may still be held where it can’t drop, such as a renderer forgotten with its graphics.
Sourcepub fn set_waker(&self, waker: Option<Waker>)
pub fn set_waker(&self, waker: Option<Waker>)
Calls waker, from the spawning thread, whenever a task arrives
while none were queued, so that the host of a local pool knows to
run it.
Sourcepub fn set_panic_handler(&self, handler: Option<PanicHandler>)
pub fn set_panic_handler(&self, handler: Option<PanicHandler>)
Calls handler with the message of each task that panics, after the
panic hook reported it. The task ends as any other, and the pool goes
on, so the owner of what the task worked on fails it.