pub struct Pool { /* private fields */ }Expand description
A pool of worker threads that execute submitted tasks concurrently.
The Pool manages a set of worker threads, each with its own local
work queue. Tasks are distributed between threads using a global
Injector and work stealing between local queues.
When dropped, the pool gracefully shuts down by preventing new submissions and joining all worker threads.
§Examples
use foofighters::pool::PoolBuilder;
let pool = PoolBuilder::new()
.set_worker_count(4)
.build();
pool.spawn(|| println!("Task executed!"));
// The pool is automatically joined when dropped.Implementations§
Source§impl Pool
impl Pool
Sourcepub fn spawn<T>(&self, task: T) -> TaskSubmission
pub fn spawn<T>(&self, task: T) -> TaskSubmission
Submits a new task to the pool for concurrent execution.
The task must implement FnOnce() + Send + 'static.
If the pool has been shut down, the task will be rejected
with TaskSubmission::Blocked.
§Examples
use foofighters::pool::{PoolBuilder, TaskSubmission};
let pool = PoolBuilder::new().build();
let result = pool.spawn(|| println!("Running a task"));
assert!(result.into_result().is_ok());Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Pool
impl !UnwindSafe for Pool
impl Freeze for Pool
impl Send for Pool
impl Sync for Pool
impl Unpin for Pool
impl UnsafeUnpin for Pool
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