[][src]Struct flo_stream::ExpiringPublisher

pub struct ExpiringPublisher<Message> { /* fields omitted */ }

An 'expiring' publisher is one that responds to backpressure from its subscribers by expiring the most recent message.

Usually when a subscriber stalls in processing, a publisher will refuse to accept further messages and block. This will avoid blocking by instead expiring messages that cannot be processed.

This is useful in a few situations. One important example is distributing state: say you want to indicate to another thread what your current state is, but if it's busy you don't want to wait for it to consume the previous state before you can finish updating the latest state.

Another example is signalling. An ExpiringPublisher<()> can be used to signal that an event has occurred but will not block if all subscribers have not responded in the case where the event occurs multiple times.

Methods

impl<Message: Clone> ExpiringPublisher<Message>[src]

pub fn new(buffer_size: usize) -> ExpiringPublisher<Message>[src]

Creates a new expiring publisher with a particular buffer size

Once a subscriber has buffer_size messages, this publisher will start to drop the oldest messages.

pub fn count_subscribers(&self) -> usize[src]

Counts the number of subscribers in this publisher

pub fn republish(&self) -> Self[src]

Creates a duplicate publisher that can be used to publish to the same streams as this object

Trait Implementations

impl<Message> Drop for ExpiringPublisher<Message>[src]

impl<Message: 'static + Send + Clone> MessagePublisher for ExpiringPublisher<Message>[src]

type Message = Message

fn subscribe(&mut self) -> Subscriber<Message>[src]

Subscribes to this publisher

Subscribers only receive messages sent to the publisher after they are created.

fn when_ready(&mut self) -> BoxFuture<'static, MessageSender<Message>>[src]

Reserves a space for a message with the subscribers, returning when it's ready

fn when_empty(&mut self) -> BoxFuture<'static, ()>[src]

Waits until all subscribers have consumed all pending messages

Auto Trait Implementations

impl<Message> RefUnwindSafe for ExpiringPublisher<Message>

impl<Message> Send for ExpiringPublisher<Message> where
    Message: Send

impl<Message> Sync for ExpiringPublisher<Message> where
    Message: Send

impl<Message> Unpin for ExpiringPublisher<Message>

impl<Message> UnwindSafe for ExpiringPublisher<Message>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.