pub struct OperationQueue { /* private fields */ }Expand description
A queue that performs asynchronous operations in order.
Implementations§
Source§impl OperationQueue
impl OperationQueue
Sourcepub fn new(
spawn_task: fn(fut: Pin<Box<dyn Future<Output = ()>>>),
) -> OperationQueue
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.
Sourcepub fn start(&self, runners: u32) -> Result<(), Error>
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.
Sourcepub async fn enqueue(
&self,
op: Box<dyn ErasedQueuedOperation>,
) -> Result<(), Error>
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.
Sourcepub fn running(&self) -> bool
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).