pub struct JobPool<R: Send + 'static> { /* private fields */ }Expand description
Fixed workers with one bound on all outstanding CPU work/results.
R and closures must be Send + 'static. Capacity bounds job/result counts,
not payload bytes; game code must bound its own inputs/results too. Polling
releases a slot. Unconsumed cancelled completions still occupy slots until
received, so cancellation cannot silently grow the completion queue.
Implementations§
Source§impl<R: Send + 'static> JobPool<R>
impl<R: Send + 'static> JobPool<R>
Sourcepub fn new(workers: usize, capacity: usize) -> Result<Self, JobPoolError>
pub fn new(workers: usize, capacity: usize) -> Result<Self, JobPoolError>
Starts workers threads and permits at most capacity outstanding jobs.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Bound shared by queued, running, and unconsumed completed jobs.
Sourcepub fn pending(&self) -> usize
pub fn pending(&self) -> usize
Current outstanding count. This is a momentary snapshot with multiple callers.
Sourcepub fn try_submit<F>(&self, work: F) -> Result<JobHandle, SubmitError<F>>
pub fn try_submit<F>(&self, work: F) -> Result<JobHandle, SubmitError<F>>
Attempts submission without waiting for capacity. Errors retain work.
Sourcepub fn try_recv(&self) -> Option<Completion<R>>
pub fn try_recv(&self) -> Option<Completion<R>>
Receives one completion without waiting, releasing one capacity slot. Cancelled payloads are dropped before returning, including cancellation after the worker finished. Cancellation after receipt cannot revoke data.
Sourcepub fn shutdown(&mut self)
pub fn shutdown(&mut self)
Drops queued/completed work, signals running jobs, and joins workers. Idempotent. Running jobs must cooperate or finish before this returns. If the pool’s last owner is dropped by its own job, that worker exits after the job returns instead of attempting to join itself.