Crate flume_overwrite

Crate flume_overwrite 

Source
Expand description

§Flume Overwrite

A library that provides bounded channels with overwrite capability, built on top of the flume crate. When the channel reaches capacity, new messages will overwrite the oldest unread messages.

§Features

  • Bounded channels with overwrite: Messages sent to a full channel will replace the oldest messages
  • Async support: Both blocking and async send operations
  • Drain tracking: Returns information about which messages were overwritten

§Examples

use flume_overwrite::bounded;

// Create a channel with capacity 3
let (sender, receiver) = bounded(3);

// Send messages normally when under capacity
sender.send_overwrite(1).unwrap();
sender.send_overwrite(2).unwrap();
sender.send_overwrite(3).unwrap();

// This will overwrite the first message (1)
let overwritten = sender.send_overwrite(4).unwrap();
assert_eq!(overwritten, Some(vec![1]));

// Receive the remaining messages
assert_eq!(receiver.recv().unwrap(), 2);
assert_eq!(receiver.recv().unwrap(), 3);
assert_eq!(receiver.recv().unwrap(), 4);

Structs§

OverwriteSender
A sender that can overwrite old messages when the channel reaches capacity.

Functions§

bounded
Creates a bounded channel with overwrite capability.