Crates.io | replay-channel |
lib.rs | replay-channel |
version | 0.1.12 |
source | src |
created_at | 2024-03-16 19:53:44.09167 |
updated_at | 2024-03-19 16:58:10.359797 |
description | A broadcast channel where new receivers replay all past messages before receiving new ones. |
homepage | |
repository | https://github.com/freenet/replay-channel |
max_upload_size | |
id | 1175932 |
size | 14,574 |
ReplayChannel
is a Rust library that lets you create a channel where messages are broadcast to all
receivers. Importantly, if a new receiver is added later, they'll get all previously sent messages
until they are caught up with the sender.
Developed by Ian Clarke for the Freenet Project.
ReplayChannel
stores all sent messages, so the memory usage is proportional to the number of
messages sent. Because of this the number of messages sent should be bounded.
To use ReplayChannel
, add it to your project's Cargo.toml
:
$ cargo add replay-channel
let replay_channel = ReplayChannel::new();
let sender = replay_channel.sender();
sender.send("message 1");
sender.send("message 2");
let mut receiver = replay_channel.receiver();
assert_eq!(receiver.receive().await, "message 1");
assert_eq!(receiver.receive().await, "message 2");
let mut new_receiver = replay_channel.receiver();
assert_eq!(new_receiver.receive().await, "message 1");
assert_eq!(new_receiver.receive().await, "message 2");
sender.send("message 3");
assert_eq!(new_receiver.receive().await, "message 3");
Available under the MIT license.