Skip to main content

PoolJob

Struct PoolJob 

Source
pub struct PoolJob { /* private fields */ }
Expand description

Type-erased pool job with a cancellation path for queued work.

PoolJob is a low-level extension point for building custom services on top of super::thread_pool::ThreadPool. The pool calls the run callback after a worker takes the job, or the cancel callback if the job is still queued during immediate shutdown.

Implementations§

Source§

impl PoolJob

Source

pub fn new( run: Box<dyn FnOnce() + Send + 'static>, cancel: Box<dyn FnOnce() + Send + 'static>, ) -> Self

Creates a pool job from run and cancel callbacks.

§Parameters
  • run - Callback executed once a worker starts this job.
  • cancel - Callback executed if this job is cancelled while queued.
§Returns

A type-erased job accepted by super::thread_pool::ThreadPool::submit_job.

Source

pub fn from_task<C, R, E>(task: C, completion: TaskCompletion<R, E>) -> Self
where C: Callable<R, E> + Send + 'static, R: Send + 'static, E: Send + 'static,

Creates a pool job from a typed callable task and completion endpoint.

§Parameters
  • task - Callable task to execute when a worker starts this job.
  • completion - Completion endpoint used to publish the typed result or cancellation.
§Returns

A type-erased job that runs the task on worker start and cancels the completion endpoint if the job is abandoned while queued.

Auto Trait Implementations§

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.