Skip to main content

OperationQueue

Struct OperationQueue 

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

A queue that performs asynchronous operations in order.

Implementations§

Source§

impl OperationQueue

Source

pub fn new( spawn_task: fn(fut: Pin<Box<dyn Future<Output = ()>>>), ) -> OperationQueue

Creates a new operation queue.

The function provided as argument is used when spawning new runners, e.g. tokio::task::spawn_local. It must not be blocking.

Source

pub fn start(&self, runners: u32) -> Result<(), Error>

Starts the given number of runners that consume new items pushed to the queue.

A runner loops infinitely, performing operations as they get queued.

An error can be returned if the queue has previously been stopped.

Source

pub async fn enqueue( &self, op: Box<dyn ErasedQueuedOperation>, ) -> Result<(), Error>

Pushes an operation to the back of the queue.

This function can be used with any type that implements QueuedOperation, since ErasedQueuedOperation is automatically implemented for all such implementations.

An error can be returned if the queue has been stopped.

Source

pub async fn stop(&self)

Stops the queue.

Operations that have already been queued up will still be performed, but any call to start or enqueue following a call to stop will fail.

Source

pub fn running(&self) -> bool

Checks whether one or more runner(s) is currently active.

If a runner has been created but isn’t running yet, it is still included in this count. Thus a runner being active means it’s in any state other than fully stopped.

This method also returns false if there aren’t any runners (e.g. if the queue hasn’t been started yet, or it has been stopped).

Source

pub fn idle(&self) -> bool

Checks whether all runners are currently waiting for a new operation to perform.

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