Skip to main content

JobPool

Struct JobPool 

Source
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>

Source

pub fn new(workers: usize, capacity: usize) -> Result<Self, JobPoolError>

Starts workers threads and permits at most capacity outstanding jobs.

Source

pub fn capacity(&self) -> usize

Bound shared by queued, running, and unconsumed completed jobs.

Source

pub fn pending(&self) -> usize

Current outstanding count. This is a momentary snapshot with multiple callers.

Source

pub fn try_submit<F>(&self, work: F) -> Result<JobHandle, SubmitError<F>>
where F: FnOnce(Cancellation) -> R + Send + 'static,

Attempts submission without waiting for capacity. Errors retain work.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<R: Send + 'static> Drop for JobPool<R>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<R> !RefUnwindSafe for JobPool<R>

§

impl<R> !UnwindSafe for JobPool<R>

§

impl<R> Freeze for JobPool<R>
where Arc<Shared<R>>: Freeze,

§

impl<R> Send for JobPool<R>
where Arc<Shared<R>>: Send,

§

impl<R> Sync for JobPool<R>
where Arc<Shared<R>>: Sync,

§

impl<R> Unpin for JobPool<R>
where Arc<Shared<R>>: Unpin,

§

impl<R> UnsafeUnpin for JobPool<R>
where Arc<Shared<R>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Component for T
where T: Send + Sync + 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.