pub struct SubscriberGroup<T: Copy, const N: usize> { /* private fields */ }Expand description
A group of N logical subscribers backed by a single ring read.
All N logical subscribers share one cursor —
try_recv performs one seqlock read
and a single cursor increment, eliminating the N-element sweep loop.
let (mut p, subs) = photon_ring::channel::<u64>(64);
let mut group = subs.subscribe_group::<4>();
p.publish(42);
assert_eq!(group.try_recv(), Ok(42));Implementations§
Source§impl<T: Copy, const N: usize> SubscriberGroup<T, N>
impl<T: Copy, const N: usize> SubscriberGroup<T, N>
Sourcepub fn try_recv(&mut self) -> Result<T, TryRecvError>
pub fn try_recv(&mut self) -> Result<T, TryRecvError>
Try to receive the next message for the group.
Performs a single seqlock read and one cursor increment — no N-element sweep needed since all logical subscribers share one cursor.
Sourcepub fn recv_with(&mut self, strategy: WaitStrategy) -> T
pub fn recv_with(&mut self, strategy: WaitStrategy) -> T
Block until the next message using the given WaitStrategy.
Like Subscriber::recv_with, but for the grouped fast path.
§Example
use photon_ring::{channel, WaitStrategy};
let (mut p, s) = channel::<u64>(64);
let mut group = s.subscribe_group::<2>();
p.publish(42);
assert_eq!(group.recv_with(WaitStrategy::BusySpin), 42);Sourcepub fn aligned_count(&self) -> usize
pub fn aligned_count(&self) -> usize
How many of the N logical subscribers are aligned.
With the single-cursor design all subscribers are always aligned,
so this trivially returns N.
Sourcepub fn total_received(&self) -> u64
pub fn total_received(&self) -> u64
Total messages successfully received by this group.
Sourcepub fn total_lagged(&self) -> u64
pub fn total_lagged(&self) -> u64
Total messages lost due to lag (group fell behind the ring).
Sourcepub fn receive_ratio(&self) -> f64
pub fn receive_ratio(&self) -> f64
Ratio of received to total (received + lagged). Returns 0.0 if no messages have been processed.
Sourcepub fn recv_batch(&mut self, buf: &mut [T]) -> usize
pub fn recv_batch(&mut self, buf: &mut [T]) -> usize
Receive up to buf.len() messages in a single call.
Messages are written into the provided slice starting at index 0. Returns the number of messages received. On lag, the cursor is advanced and filling continues from the oldest available message.