Struct TaskPool

Source
pub struct TaskPool<V, P>
where P: Progressible,
{ /* private fields */ }
Expand description

A pool to manage long-running tasks.

Implementations§

Source§

impl<V, P> TaskPool<V, P>
where P: Progressible + Clone,

Source

pub fn with_lifespan(self, lifespan: Option<Duration>) -> Self

Configure the lifespan of tasks. None means that tasks will never expire. Expired tasks are purged as soon as complete is invoked. Specifying a lifespan is useful because clients might not always retrieve completed tasks. Without configuring a lifespan, such abandoned tasks accumulate over time and fill up memory.

Source

pub fn insert(&mut self, pending: P) -> (Handle, Uuid)

Insert a task’s initial progress to receive a Handle and Uuid referencing the task.

Source

pub fn retrieve(&mut self, uuid: &Uuid) -> Option<TaskState<V, P>>

Get the task state and remove it from the pool if it is done.

Source

pub fn progress(&mut self, handle: &Handle)

Report progress on a pending task. Calls Progressible::progress on the corresponding progress state.

Source

pub fn complete(&mut self, handle: Handle, value: V)

Mark the task associated to the handle as completed with a value of type T. The handle must be passed by value so that this is the final action. As a side effect expired tasks are purged.

Trait Implementations§

Source§

impl<V, P> Default for TaskPool<V, P>
where P: Progressible,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<V, P> Freeze for TaskPool<V, P>

§

impl<V, P> RefUnwindSafe for TaskPool<V, P>

§

impl<V, P> Send for TaskPool<V, P>
where P: Send, V: Send,

§

impl<V, P> Sync for TaskPool<V, P>
where P: Sync, V: Sync,

§

impl<V, P> Unpin for TaskPool<V, P>
where P: Unpin, V: Unpin,

§

impl<V, P> UnwindSafe for TaskPool<V, P>
where P: UnwindSafe, V: UnwindSafe,

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, 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.