Publisher

Trait Publisher 

Source
pub trait Publisher<T> {
    // Required methods
    fn publish<'life0, 'life1, 'async_trait>(
        &'life0 self,
        payload: &'life1 T,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn close<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A non-locking replacement for Sink.

Interactions with a Sink generally require exclusive mutable access to the underlying sink, which is problematic when working in a highly concurrent system. While implementations of Sink, like futures::channel::mpsc::Sender, are generally cloneable, the Sink trait itself does not require any such guarantees, which means that code that simply relies on Sink may not make any assumptions about the ability to clone the underlying Sink. As such, we provide a trait that is functionally equivalent to Sink, but does not require exclusive mutable access to publish messages.

Required Methods§

Source

fn publish<'life0, 'life1, 'async_trait>( &'life0 self, payload: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Publish a message.

The implementation should be take care of serializing the payload before publishing.

Source

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Close the publisher, signaling to any receivers that no more messages will be published.

Implementations on Foreign Types§

Source§

impl<T: Sync, P> Publisher<T> for Pin<P>
where P: DerefMut + Unpin + Sync, P::Target: Publisher<T> + Sync,

Source§

fn publish<'life0, 'life1, 'async_trait>( &'life0 self, payload: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl<T: Sync, P: ?Sized + Publisher<T> + Sync> Publisher<T> for Box<P>

Source§

fn publish<'life0, 'life1, 'async_trait>( &'life0 self, payload: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§

Source§

impl<P, F, Input, Output> Publisher<Input> for With<P, F, Output>
where P: Publisher<Output> + Sync, Input: Sync, Output: Send + Sync, F: Fn(&Input) -> Result<Output> + Sync,

Source§

impl<T, Inner> Publisher<T> for CoordinatedPublisher<T, Inner>
where T: Send + Sync, Inner: Publisher<T> + Sync,

Source§

impl<T: Serializable> Publisher<T> for AMQPPublisher<T>

Source§

impl<T: Serializable> Publisher<T> for InMemoryPublisher<T>