Skip to main content

Subscriber

Struct Subscriber 

Source
pub struct Subscriber { /* private fields */ }
Expand description

A live subscription to a track, used to read its groups.

Created via Consumer::subscribe, or directly from a Producer for an in-process track. Carries this subscriber’s Subscription preferences, which feed the producer’s aggregate.

§Local cursor vs wire preference

Group bounds exist at two levels, and setting one does not imply the other:

They stay separate because their scopes differ: a subscriber can’t filter by the aggregate, since another subscriber can widen it, and the publisher can’t honor a cursor it’s never told about. So setting only the cursor still transfers the skipped groups, and setting only the preference still returns groups another subscriber asked for. Set both to skip them and avoid the transfer.

Implementations§

Source§

impl Subscriber

Source

pub fn info(&self) -> &Info

The track’s Info, resolved when the subscription was established.

Free, unlike Consumer::info: subscribing already waited for the info (SUBSCRIBE_OK on the wire), so a subscriber always has it.

Source

pub fn name(&self) -> &str

The track’s name, unique within its broadcast.

Source

pub fn control(&self) -> SubscriberControl

Create a handle for updating this subscriber’s delivery preferences.

Source

pub fn poll_recv_group( &mut self, waiter: &Waiter, ) -> Poll<Result<Option<Consumer>>>

Poll for the next group in arrival order, without blocking.

Returns every group exactly once in the order it landed on the wire, which may be out of sequence due to network reordering or loss. Use Self::poll_next_group if you only want groups whose sequence number is higher than any previously returned.

Returns Poll::Ready(Ok(Some(group))) when a group is available, Poll::Ready(Ok(None)) when the track is finished, Poll::Ready(Err(e)) when the track has been aborted, or Poll::Pending when no group is available yet.

Source

pub async fn recv_group(&mut self) -> Result<Option<Consumer>>

Receive the next group in arrival order.

Every group is returned exactly once, in the order it landed on the wire, which may be out of sequence due to network reordering or loss. Use Self::next_group if you only want groups whose sequence number is higher than any previously returned.

Source

pub fn poll_recv_datagram( &mut self, waiter: &Waiter, ) -> Poll<Result<Option<Datagram>>>

Poll for the next datagram in arrival order, without blocking.

Datagrams are a separate best-effort channel from groups (see Producer::append_datagram); they share only the sequence namespace. A consumer that falls too far behind silently loses the oldest datagrams. Returning a datagram advances Self::poll_next_group past that sequence.

Returns Poll::Ready(Ok(Some(datagram))) when one is available, Poll::Ready(Ok(None)) when the track is finished, Poll::Ready(Err(e)) when the track is aborted, or Poll::Pending when none is buffered yet.

Source

pub async fn recv_datagram(&mut self) -> Result<Option<Datagram>>

Receive the next datagram in arrival order.

A best-effort channel parallel to Self::recv_group; the two share only the sequence namespace. To receive both concurrently from one subscriber, poll Self::poll_next_group (or Self::poll_recv_group) and Self::poll_recv_datagram together in a single poll closure (sequential &mut borrows), rather than awaiting the two recv futures at once.

Source

pub fn poll_next_group( &mut self, waiter: &Waiter, ) -> Poll<Result<Option<Consumer>>>

Poll for the next group with a higher sequence number than any previously returned.

Late arrivals (sequence at or below the last returned) are silently skipped, so this produces a monotonically increasing sequence at the cost of dropping out-of-order groups. Use Self::poll_recv_group to see every group in arrival order instead.

Honors the cap set by Self::end_at: groups with sequence past the cap are left in the producer’s cache and become eligible again if the cap is raised or removed.

Source

pub async fn next_group(&mut self) -> Result<Option<Consumer>>

Return the next group with a higher sequence number than any previously returned.

Late arrivals (sequence at or below the last returned) are silently skipped, so this produces a monotonically increasing sequence at the cost of dropping out-of-order groups. Use Self::recv_group to see every group in arrival order instead.

Source

pub fn poll_read_frame( &mut self, waiter: &Waiter, ) -> Poll<Result<Option<Frame>>>

A helper that calls Self::poll_next_group and returns its first frame (timestamp and payload), skipping the rest of the group. Intended for single-frame groups (see Producer::write_frame).

Source

pub async fn read_frame(&mut self) -> Result<Option<Frame>>

Read a single full frame (timestamp and payload) from the next group in sequence order.

See Self::poll_read_frame for semantics.

Source

pub fn is_clone(&self, other: &Self) -> bool

Whether other was cloned from this subscriber (shares the same underlying state).

Source

pub fn poll_finished(&mut self, waiter: &Waiter) -> Poll<Result<u64>>

Poll for the track’s declared final sequence, without blocking.

Source

pub async fn finished(&mut self) -> Result<u64>

Block until the track declares its end, returning the exclusive final sequence (also the total group count), or the cause on an abort.

Resolves as soon as the boundary is known, which may be ahead of the live edge when the producer finished via Producer::finish_at. This reports the declared end, not that every group has arrived: drive Self::recv_group / Self::next_group until they yield None to observe the track fully drained.

Source

pub fn start_at(&mut self, sequence: u64)

Start this subscriber’s read cursor at the given sequence.

A local filter, not a request: it doesn’t tell the publisher anything, so the skipped groups are still delivered and simply not returned. To ask the publisher to start there instead, set Subscription::group_start via Self::update. See Local cursor vs wire preference.

Source

pub fn end_at(&mut self, sequence: impl Into<Option<u64>>)

Cap this subscriber’s read cursor at the given sequence (inclusive), or remove the cap entirely.

Accepts a bare u64 (cap), Some(u64), or None (uncap).

A local filter, not a request; Subscription::group_end is the wire-level counterpart. See Local cursor vs wire preference.

Affects Self::next_group only: groups beyond the cap stay in the producer’s cache rather than being skipped past, so a later call to Self::end_at with a higher value (or None) makes them available again. Lowering the cap below the consumer’s current cursor parks the consumer until the cap is raised.

Source

pub fn subscription(&self) -> Subscription

This subscriber’s current preferences.

Source

pub fn update(&mut self, subscription: Subscription) -> Result<()>

Replace this subscriber’s delivery preferences.

Stored verbatim; the publisher’s latency window is applied to the aggregate, not here (see Producer::subscription). Returns Error::Closed if the track already ended; the update is meaningless at that point and can usually be ignored.

Source

pub fn latest(&self) -> Option<u64>

Return the latest sequence number in the track.

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> MaybeSync for T
where T: Sync,

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more