Expand description
Static SPSC (Single-Producer Single-Consumer) channel.
Const-generic ring buffer with atomic head/tail indices, split into
Sender/Receiver halves. send()/recv() return real Futures
usable with .await from async fn tasks โ no heap allocation.
โ
static CHAN: rivet::sync::Channel<u32, 8> = rivet::sync::Channel::new();
#[rivet::task(priority = 1)]
async fn producer() {
let (mut tx, _) = CHAN.split();
loop {
tx.send(42).await;
}
}
#[rivet::task(priority = 0)]
async fn consumer() {
let (_, mut rx) = CHAN.split();
loop {
let val = rx.recv().await;
}
}Structsยง
- Channel
- A lock-free SPSC ring buffer. Usable capacity is
N - 1. - Receiver
- Receiving half of an SPSC channel.
- Recv
- Future returned by
Receiver::recv. - SendFut
- Future returned by
Sender::send. - Sender
- Sending half of an SPSC channel.