Skip to main content

Subscriber

Struct Subscriber 

Source
pub struct Subscriber<T: Copy> { /* private fields */ }
Expand description

The read side of a Photon SPMC channel.

Each subscriber has its own cursor — no contention between consumers.

Implementations§

Source§

impl<T: Copy> Subscriber<T>

Source

pub fn try_recv(&mut self) -> Result<T, TryRecvError>

Try to receive the next message without blocking.

Source

pub fn recv(&mut self) -> T

Spin until the next message is available and return it.

Uses a two-phase spin strategy: bare spin for the first 64 iterations (minimum wakeup latency, ~0 ns reaction time), then PAUSE-based spin (saves power, yields to SMT sibling). On Skylake+, PAUSE adds ~140 cycles of delay per iteration — the bare-spin phase avoids this penalty when the message arrives quickly (typical for cross-thread pub/sub).

Source

pub fn latest(&mut self) -> Option<T>

Skip to the latest published message (discards intermediate ones).

Returns None only if nothing has been published yet. Under heavy producer load, retries internally if the target slot is mid-write.

Source

pub fn pending(&self) -> u64

How many messages are available to read (capped at ring capacity).

Trait Implementations§

Source§

impl<T: Copy + Send> Send for Subscriber<T>

Auto Trait Implementations§

§

impl<T> Freeze for Subscriber<T>

§

impl<T> !RefUnwindSafe for Subscriber<T>

§

impl<T> Sync for Subscriber<T>
where T: Send,

§

impl<T> Unpin for Subscriber<T>

§

impl<T> UnsafeUnpin for Subscriber<T>

§

impl<T> !UnwindSafe for Subscriber<T>

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.