Skip to main content

SubscriberGroup

Struct SubscriberGroup 

Source
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>

Source

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.

Source

pub fn recv(&mut self) -> T

Spin until the next message is available.

Source

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);
Source

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.

Source

pub fn pending(&self) -> u64

Number of messages available to read (capped at ring capacity).

Source

pub fn total_received(&self) -> u64

Total messages successfully received by this group.

Source

pub fn total_lagged(&self) -> u64

Total messages lost due to lag (group fell behind the ring).

Source

pub fn receive_ratio(&self) -> f64

Ratio of received to total (received + lagged). Returns 0.0 if no messages have been processed.

Source

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.

Trait Implementations§

Source§

impl<T: Copy, const N: usize> Drop for SubscriberGroup<T, N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Copy + Send, const N: usize> Send for SubscriberGroup<T, N>

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for SubscriberGroup<T, N>

§

impl<T, const N: usize> !RefUnwindSafe for SubscriberGroup<T, N>

§

impl<T, const N: usize> !Sync for SubscriberGroup<T, N>

§

impl<T, const N: usize> Unpin for SubscriberGroup<T, N>

§

impl<T, const N: usize> UnsafeUnpin for SubscriberGroup<T, N>

§

impl<T, const N: usize> !UnwindSafe for SubscriberGroup<T, N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.