pub struct ExpiringPublisher<Message> { /* private fields */ }Expand description
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.
Implementations§
Source§impl<Message: Clone> ExpiringPublisher<Message>
impl<Message: Clone> ExpiringPublisher<Message>
Sourcepub fn new(buffer_size: usize) -> ExpiringPublisher<Message>
pub fn new(buffer_size: usize) -> ExpiringPublisher<Message>
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.
Sourcepub fn count_subscribers(&self) -> usize
pub fn count_subscribers(&self) -> usize
Counts the number of subscribers in this publisher
Trait Implementations§
Source§impl<Message> Drop for ExpiringPublisher<Message>
impl<Message> Drop for ExpiringPublisher<Message>
Source§impl<Message: 'static + Send + Clone> MessagePublisher for ExpiringPublisher<Message>
impl<Message: 'static + Send + Clone> MessagePublisher for ExpiringPublisher<Message>
Source§fn subscribe(&mut self) -> Subscriber<Message>
fn subscribe(&mut self) -> Subscriber<Message>
Subscribes to this publisher
Subscribers only receive messages sent to the publisher after they are created.
Source§fn when_ready(&mut self) -> BoxFuture<'static, MessageSender<Message>>
fn when_ready(&mut self) -> BoxFuture<'static, MessageSender<Message>>
Reserves a space for a message with the subscribers, returning when it’s ready
Source§fn when_empty(&mut self) -> BoxFuture<'static, ()>
fn when_empty(&mut self) -> BoxFuture<'static, ()>
Waits until all subscribers have consumed all pending messages
Source§fn is_closed(&self) -> bool
fn is_closed(&self) -> bool
Returns true if this publisher is closed (will not publish any further messages to its subscribers)
Source§fn when_closed(&self) -> BoxFuture<'static, ()>
fn when_closed(&self) -> BoxFuture<'static, ()>
Future that returns when this publisher is closed