Expand description
§selectables
Lock-free channels with a unified recv-arm selection model.
The crate provides multiple channel flavors that can be selected with the same
recv-based protocol, including non-blocking and timed fallback behavior.
§Channel modules
- unbounded_mpmc lock-free unbounded multi-producer, multi-consumer channel.
- bounded_mpmc lock-free bounded multi-producer, multi-consumer channel.
- bounded_mpsc lock-free bounded multi-producer, single-consumer channel.
- unbounded_mpsc lock-free unbounded multi-producer, single-consumer channel.
- bounded_broadcast bounded multi-producer, multi-receiver broadcast channel with per-receiver lag detection and independent cursors.
- oneshot single-send/single-delivery channel compatible with recv select arms.
- watch latest-value broadcast channel with versioned change notifications.
- rendezvous zero-buffer synchronous handoff channel.
§Selection model
- select! supports
recv(rx) -> msg => { ... }andsend(tx, val) -> res => { ... }arms. - Non-blocking fallback:
default => { ... }. - Timed fallback:
default(duration) => { ... }. - Low-level builder API is provided by Select and SelectedOperation.
§Timers
- interval::interval and interval::interval_at create repeating timer receivers.
§Error model
- RecvError for blocking receive/completion failures. Includes
Lagged { skipped }for bounded broadcast channels when a receiver falls behind senders. - [error::TryRecvError] for non-blocking receive attempts.
- SendError for failed sends that return ownership of the message.
§Lag handling (broadcast channels only)
When using bounded_broadcast, receivers may encounter Lagged { skipped } if they fall
behind the senders. This is normal and indicates the ring buffer wrapped around before the
receiver caught up. Recommended handling:
ⓘ
match rx.recv() {
Ok(msg) => process(msg),
Err(RecvError::Lagged { skipped }) => {
log::warn!("Receiver lagged by {} messages; recovered", skipped);
// Receiver cursor was automatically advanced; next recv will get oldest available
}
Err(RecvError::Disconnected) => {
log::info!("All senders disconnected");
break;
}
}See bounded_broadcast module docs for detailed lag recovery patterns.
§Quick example
use std::time::Duration;
use selectables::{bounded_mpmc, select};
let (tx, rx) = bounded_mpmc::channel::<i32>(1);
tx.send(7).unwrap();
select! {
recv(rx) -> msg => assert_eq!(msg, Ok(7)),
default(Duration::from_millis(10)) => panic!("unexpected timeout"),
}Modules§
- bounded_
broadcast - Bounded multi-producer, multi-receiver broadcast channel with per-receiver lag detection.
- bounded_
mpmc - Bounded multi-producer, multi-consumer channel with lock-free send and recv.
- bounded_
mpsc - Bounded multi-producer, single-consumer channel with lock-free send and recv.
- interval
- Repeating timer channel, selectable via
recvarms. - oneshot
- Single-send, single-delivery channel for one-time messages.
- rendezvous
- Rendezvous channel: synchronous, zero-buffer handoff between sender and receiver.
- unbounded_
mpmc - Unbounded lock-free multi-producer, multi-consumer channel.
- unbounded_
mpsc - Unbounded lock-free multi-producer, single-consumer channel.
- watch
- Latest-value broadcast channel with versioned change notifications.
Macros§
- select
- Dispatch to the first ready channel operation.
Structs§
- Select
- Selected
Operation - Returned by
Select::select(). Carries the winning arm’s index. - Send
Error
Enums§
- Recv
Error - Error returned by blocking recv operations.
Traits§
- Selectable
Receiver - Trait for receivers that can participate in
recvarms ofselect!. - Selectable
Sender - Trait for senders that can participate in
sendarms ofselect!.