Skip to main content

Crate fanring

Crate fanring 

Source
Expand description

Fast typed in-process MPSC and MPMC channels built from SPSC rings.

Every sender owns one bounded ring. Producers therefore avoid contention on a shared queue tail, while receiver-side batching amortizes synchronization. Sender registration is dynamic and dropped lane slots are reused.

§Choose a channel

  • mpsc has one receiver, preserves FIFO within each sender lane, and has the smallest receive-side overhead.
  • mpmc has cloneable competing receivers and relaxed ordering. Receivers stage batches in bounded queues that other receivers can steal.

Both variants provide nonblocking, blocking, timeout, and deadline APIs. Capacity is a high-water mark per sender, not one shared channel bound.

§Teardown

Constructors default to teardown::Deferred: unread ring payloads may remain alive until their sender drops. Choose teardown::Coordinated with mpsc::channel_with_policy or mpmc::channel_with_policy to reclaim payloads independently of idle sender lifetimes. An overlapping send can finish cleanup after receiver drop returns, without blocking that drop on a paused producer. The choice is per channel and inherited by cloned handles.

§Example

use fanring::mpsc;

let (mut tx0, mut rx) = mpsc::channel(64);
let mut tx1 = tx0.try_clone().expect("receiver is alive");

tx0.send("first").unwrap();
tx1.send("second").unwrap();

let mut values = [rx.recv().unwrap(), rx.recv().unwrap()];
values.sort_unstable();
assert_eq!(values, ["first", "second"]);

See each channel module for its exact ordering, capacity, and disconnection contracts.

Modules§

mpmc
Dynamic MPMC channel built from one bounded SPSC ring per sender.
mpsc
Dynamic MPSC channel built from one bounded SPSC ring per sender.
teardown
Choose when unread payloads are destroyed after the last receiver drops.

Enums§

WaitStrategy
Policy used by synchronous blocking operations before they park.