Skip to main content

EventQueue

Trait EventQueue 

Source
pub trait EventQueue<T>:
    Send
    + Sync
    + 'static {
    // Required methods
    fn new(capacity: Option<usize>) -> Self;
    fn publish(&self, item: T) -> impl Future<Output = Result<()>> + Send;
    fn try_publish(&self, item: T) -> Result<(), TryPublishError<T>>;
    fn close(&self) -> impl Future<Output = ()> + Send;
    fn recv(&self) -> impl Future<Output = Result<T>> + Send;
}
Expand description

Async queue used by generated mediators to enqueue events and dequeue them in a background processing loop.

§Type parameters

  • T — The job/enum type that the generated mediator uses to represent all possible events across its subscribed modules.

Required Methods§

Source

fn new(capacity: Option<usize>) -> Self

Create a new queue.

Some(capacity) requests a bounded queue; None requests an unbounded queue. Adapters may ignore the hint if the underlying channel does not support bounding.

Source

fn publish(&self, item: T) -> impl Future<Output = Result<()>> + Send

Enqueue an item.

Returns Error::EventPublishingError if the channel is closed or full.

Source

fn try_publish(&self, item: T) -> Result<(), TryPublishError<T>>

Attempt to enqueue an item without waiting for queue capacity.

Returns the original item in TryPublishError when the queue is full or no longer accepts events.

Source

fn close(&self) -> impl Future<Output = ()> + Send

Stop accepting new items.

Items for which Self::publish has already returned Ok(()) remain available to receivers. Generated shutdown then enqueues internal worker-control items behind that accepted work.

Source

fn recv(&self) -> impl Future<Output = Result<T>> + Send

Dequeue the next item.

Returns Error::EventProcessingError if the channel is closed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§