pub struct WorkerPool { /* private fields */ }Expand description
Fixed-size thread pool with bounded FIFO task queue.
Uses crossbeam-channel for lock-free multi-consumer dispatch —
each worker calls recv() directly, no mutex.
Implementations§
Source§impl WorkerPool
impl WorkerPool
Sourcepub fn new(size: usize) -> Self
pub fn new(size: usize) -> Self
Create a pool with size worker threads and bounded channel.
Channel capacity = 4 × size (provides backpressure without starving).
Sourcepub fn default_size() -> Self
pub fn default_size() -> Self
Create a pool sized to the machine’s parallelism, clamped [2, 18].
Sourcepub fn submit<F>(&self, f: F)
pub fn submit<F>(&self, f: F)
Submit a task to the pool. Blocks if the queue is full (backpressure). Panics if the pool has been shut down.
Sourcepub fn submit_with_result<F, R>(&self, f: F) -> Receiver<R>
pub fn submit_with_result<F, R>(&self, f: F) -> Receiver<R>
Submit a task and get a receiver for its result.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Signal all workers to drop pending tasks.
Already-running tasks will finish, but queued tasks are skipped.
Reset with reset_cancel().
Sourcepub fn reset_cancel(&self)
pub fn reset_cancel(&self)
Clear the cancellation flag — pool resumes normal execution.
Sourcepub fn queue_depth(&self) -> usize
pub fn queue_depth(&self) -> usize
Approximate number of tasks waiting in the queue.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WorkerPool
impl !RefUnwindSafe for WorkerPool
impl Send for WorkerPool
impl Sync for WorkerPool
impl Unpin for WorkerPool
impl UnsafeUnpin for WorkerPool
impl !UnwindSafe for WorkerPool
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more