pub struct PoolJob { /* private fields */ }Expand description
Type-erased pool job with separate detached and cancellable forms.
Implementations§
Source§impl PoolJob
impl PoolJob
Sourcepub fn new(
run: Box<dyn FnOnce() + Send + 'static>,
cancel: Box<dyn FnOnce() + Send + 'static>,
) -> Self
pub fn new( run: Box<dyn FnOnce() + Send + 'static>, cancel: Box<dyn FnOnce() + Send + 'static>, ) -> Self
Creates a custom cancellable job with no acceptance callback.
Higher-level services that maintain their own task state usually want
Self::with_accept instead, so they can publish acceptance only after
the backing pool has accepted the job.
Custom callbacks run synchronously and should not block. Panics raised
by run or cancel are caught and ignored by the pool job wrapper.
§Parameters
run- Callback executed when a worker starts this job.cancel- Callback executed if the accepted job is cancelled before it starts.
§Returns
A custom type-erased job accepted by thread pools.
Sourcepub fn with_accept(
accept: Box<dyn FnOnce() + Send + 'static>,
run: Box<dyn FnOnce() + Send + 'static>,
cancel: Box<dyn FnOnce() + Send + 'static>,
) -> Self
pub fn with_accept( accept: Box<dyn FnOnce() + Send + 'static>, run: Box<dyn FnOnce() + Send + 'static>, cancel: Box<dyn FnOnce() + Send + 'static>, ) -> Self
Creates a custom cancellable job with an acceptance callback.
The pool invokes accept exactly once after the submission crosses the
acceptance boundary. If submission is rejected before acceptance, neither
accept, run, nor cancel is invoked. Custom callbacks run
synchronously and should not block. Panics raised by these callbacks are
caught and ignored by the pool job wrapper; an accept panic is reported
to the pool as a failed acceptance callback.
§Parameters
accept- Callback invoked once the pool accepts the job.run- Callback executed when a worker starts this job.cancel- Callback executed if the accepted job is cancelled before it starts.
§Returns
A custom type-erased job accepted by thread pools.