Skip to main content

Module overflow

Module overflow 

Source
Expand description

A multi-producer multi-consumer broadcast channel.

This channel supports multiple senders and multiple receivers. Each message sent by any sender is received by all receivers. If a receiver falls behind, it may miss messages, which is reported via RecvError::Lagged.

§Examples

Basic usage:

use asyncband::broadcast::overflow;

let (tx, mut rx1) = overflow::channel(16);
let mut rx2 = tx.subscribe();

tx.send(10);
tx.send(20);

assert_eq!(rx1.recv().await, Ok(10));
assert_eq!(rx1.recv().await, Ok(20));
assert_eq!(rx2.recv().await, Ok(10));
assert_eq!(rx2.recv().await, Ok(20));

Handling lag:

use asyncband::broadcast::overflow;
use asyncband::broadcast::overflow::RecvError;

let (tx, mut rx) = overflow::channel(2);

tx.send(1);
tx.send(2);
tx.send(3); // overwrites the oldest message (1)

assert_eq!(rx.recv().await, Err(RecvError::Lagged(1)));
assert_eq!(rx.recv().await, Ok(2));
assert_eq!(rx.recv().await, Ok(3));

Structs§

Receiver
A receiver handle to the broadcast channel.
Sender
A sender handle to the broadcast channel.

Enums§

RecvError
Error returned by Receiver::recv.
TryRecvError
Error returned by Receiver::try_recv.

Functions§

channel
Creates a new broadcast channel with the given hint capacity. The actual capacity may be greater than the provided capacity.