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:

  • Subscription::ranges, set via Self::update, are both a request to the publisher and this subscriber’s read filter. The publisher sees the union across every live subscriber, but each subscriber reads only the groups its own ranges cover, resolved where it is served: a live join placed by its Start::Live lag behind the latest group (or at the first to arrive, before any exists), again whenever the ranges are replaced.
  • Self::with_range narrows this subscriber’s reads further, without changing the publisher’s demand.

A group outside either is held rather than skipped past, so widening either one later makes it available again. Within both, a live join’s max decides what it still delivers, measured against the track’s live edge; a history range delivers every group.

Implementations§

Source§

impl Subscriber

Source

pub fn bill(&mut self) -> Bill

Count the payload of the groups taken from now on only as the caller delivers it, through the returned stats::Bill, rather than as it is read. A reader that drops some of what it reads, such as a gateway’s jitter buffer, takes it before its first group, so what it drops counts nothing.

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 broadcast(&self) -> &Info

The broadcast this track belongs to, as reached through the handle it came from. Its path is what a catalog’s relative broadcast references resolve against.

Source

pub fn control(&self) -> Control

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

Source

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

The next group to arrive, picking from those held unread in the subscription’s Order.

Returns each group it delivers exactly once. A reader that keeps up gets each group as it lands, out of key under network reordering or loss. One holding several unread, a backlog or a replayed cache, gets the newest first unless Order::Ascending: ask ascending to read them oldest first. A lower group that lands late is still delivered. Use Self::ordered if you only want groups whose key is higher than any previously returned.

Once means once per key: a group the publisher aborts and re-creates, or that a second route delivers too, is not handed out again. Once a group is past the budget below, the subscriber stops expecting every group before it, so a gap that old is never filled, which holds because a timed track refuses a group whose start rewinds. The exception is a cached group it skipped as stale, which a wider budget offers again.

Groups are semi-reliable, and a live join’s max is the other thing (alongside eviction and a moving start) that decides which of them arrive: a group reached only through live joins that has drifted further behind the live edge than the widest tolerates is skipped rather than handed over, so a single read walks off a whole backlog. The default Start::LATEST takes the live edge and writes the rest off; a history range (a time, position, or oldest start) reads every group it covers. Consumer::fetch_group is the way to ask for one old group outright. Across same-identity route copies, the first group any copy holds in that order is delivered first. The budget remains attached to a returned group: if it stalls while newer data advances, its pending frame read ends with Error::Old.

Honors the group range set by Self::with_range: a group beyond the cap is passed without blocking in-range groups that arrive behind it, and holds nothing here. Raising the cap, or widening the ranges, offers the groups it newly covers that the cache still holds, newest first unless Order::Ascending. Widening the budget offers the cached groups it skipped as stale and now covers the same way. Once the track finishes, a reader with nothing left in range ends.

A reader whose Subscription::ranges all end ends too, once every group in them was handed out, dropped, skipped as stale, or given up as unfillable, rather than waiting for an update to widen them: a reader that wants more keeps a range open. A Self::with_range cap never ends a read, since it may rise again, and a group it keeps out stays owed. A track an origin serves from whichever of its routes is up ends the same way, once no route it left may still deliver a group in range. Later reads return Ok(None) immediately too. Widening the ranges with Self::update resumes reading the newly covered groups without replaying any.

A group one of Subscription::ranges starts or ends inside reads only the frames they cover there. One missing the frames asked for reads Error::Lagged rather than starting short.

Returns Ok(Some(group)) when a group is available, Ok(None) when the track is finished or the ranges are read, or the error when the track has been aborted.

Source

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

The next group to arrive, picking from those held unread in the subscription’s Order.

Returns each group it delivers exactly once. A reader that keeps up gets each group as it lands, out of key under network reordering or loss. One holding several unread, a backlog or a replayed cache, gets the newest first unless Order::Ascending: ask ascending to read them oldest first. A lower group that lands late is still delivered. Use Self::ordered if you only want groups whose key is higher than any previously returned.

Once means once per key: a group the publisher aborts and re-creates, or that a second route delivers too, is not handed out again. Once a group is past the budget below, the subscriber stops expecting every group before it, so a gap that old is never filled, which holds because a timed track refuses a group whose start rewinds. The exception is a cached group it skipped as stale, which a wider budget offers again.

Groups are semi-reliable, and a live join’s max is the other thing (alongside eviction and a moving start) that decides which of them arrive: a group reached only through live joins that has drifted further behind the live edge than the widest tolerates is skipped rather than handed over, so a single read walks off a whole backlog. The default Start::LATEST takes the live edge and writes the rest off; a history range (a time, position, or oldest start) reads every group it covers. Consumer::fetch_group is the way to ask for one old group outright. Across same-identity route copies, the first group any copy holds in that order is delivered first. The budget remains attached to a returned group: if it stalls while newer data advances, its pending frame read ends with Error::Old.

Honors the group range set by Self::with_range: a group beyond the cap is passed without blocking in-range groups that arrive behind it, and holds nothing here. Raising the cap, or widening the ranges, offers the groups it newly covers that the cache still holds, newest first unless Order::Ascending. Widening the budget offers the cached groups it skipped as stale and now covers the same way. Once the track finishes, a reader with nothing left in range ends.

A reader whose Subscription::ranges all end ends too, once every group in them was handed out, dropped, skipped as stale, or given up as unfillable, rather than waiting for an update to widen them: a reader that wants more keeps a range open. A Self::with_range cap never ends a read, since it may rise again, and a group it keeps out stays owed. A track an origin serves from whichever of its routes is up ends the same way, once no route it left may still deliver a group in range. Later reads return Ok(None) immediately too. Widening the ranges with Self::update resumes reading the newly covered groups without replaying any.

A group one of Subscription::ranges starts or ends inside reads only the frames they cover there. One missing the frames asked for reads Error::Lagged rather than starting short.

Returns Ok(Some(group)) when a group is available, Ok(None) when the track is finished or the ranges are read, or the error when the track has been aborted.

Awaits poll_recv_group.

Source

pub fn ordered(self) -> Ordered

Read this track’s groups in key order instead of arrival order.

Consumes the subscriber, so one handle carries exactly one cursor: an arrival-order Subscriber or a key-order Ordered, never both at once. The two advance independently, and interleaving them produces a group stream that is neither, which is why the choice is a handle rather than a method.

Source

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

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

Source

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

The lowest group this subscriber’s ranges name, as resolved here when it last read, raised to the start of Self::with_range: None while one reaches back to the oldest group still around, or a live join still waits on the first group from the live feed.

Where a reader that waits on each group in key starts, rather than at whatever arrives first, which newest-first delivery makes the latest.

Source

pub fn is_skipped(&self, groups: Range<u64>) -> bool

Whether the publisher declared every start in groups skipped, never to be produced (see Producer::skip_groups, which appending does between groups), so no group can arrive there: true for an empty range. This ignores the subscriber’s ranges. A copy knows only the skips its wire forwarded.

What tells a reader that nothing lies between two groups, or before a track’s first. It knows only the skips recorded so far, so false means “not known skipped”: a skip still in flight reads false, as does one a local producer’s cache expired below its edge. A reader that asks once treats such a group as one with something before it.

Source

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

The track’s declared exclusive end position, or the cause on an abort. See Producer::finish_at for what the position means.

Resolves as soon as the end 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. A local session close without a declared end returns Error::Closed. Read Self::poll_recv_group (or Ordered::poll_next_group) until it yields None to observe the track fully drained.

Source

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

The track’s declared exclusive end position, or the cause on an abort. See Producer::finish_at for what the position means.

Resolves as soon as the end 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. A local session close without a declared end returns Error::Closed. Read Self::poll_recv_group (or Ordered::poll_next_group) until it yields None to observe the track fully drained.

Awaits poll_finished.

Source

pub fn with_range(self, groups: impl RangeBounds<u64>) -> Self

Limit subsequent reads to these group keys, returning self for chaining.

2..=5 includes groups 2 through 5; 2..5 excludes group 5, and ..0 is the empty range. Both bounds are assigned, in either direction: an omitted start is group 0 and an omitted end removes the cap. Lowering the floor or raising the cap offers the groups it newly covers that the cache still holds and this reader never handed out, in its Order; a group is never handed out twice while the subscription’s ranges hold it (see Self::update). Groups past the cap stay cached, and lowering the cap below the cursor waits until it rises again or the track finishes, unless bounded subscription ranges have nothing left to deliver, which ends the read. Self::poll_largest reports within these bounds.

A local filter, not a request: it tells the publisher nothing, so groups outside it are still delivered and simply not returned. To change what is requested, set Subscription::ranges via Self::update. See Local cursor vs wire preference. One exception: on a track served across route changes, lowering the floor asks the serving route again for the groups it newly covers within those ranges, since the route that delivered them may be gone.

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 max age window is applied to the aggregate, not here (see Producer::subscription). Replaced ranges resolve again here, a live join placed behind the latest group now, and widening them offers the cached groups they newly cover, even ones that arrived before the groups already read. A group read stays read while the ranges hold it; ranges replaced off it may forget it, so ranges holding it again may hand it out again, as a new subscription would. Returns Error::Closed if the track already ended; the update is meaningless at that point and can usually be ignored.

Source

pub fn poll_largest(&mut self, waiter: &Waiter) -> Poll<Option<Position>>

Poll for the track’s largest location within Self::with_range: the current one, then each newer one, and None once the track ends.

The largest is the newest group at the newest frame (0 while empty), as the source reported it and its live feed delivered since, so nothing reports until the track’s feed is live. A largest past the cap or below the floor reports nothing: the cache does not stand in for it, so a cap moved below the largest stays pending. Moving the bounds wakes a parked poll, which reports the largest once it is within them and newer than the last report.

Source

pub async fn largest(&mut self) -> Option<Position>

Poll for the track’s largest location within Self::with_range: the current one, then each newer one, and None once the track ends.

The largest is the newest group at the newest frame (0 while empty), as the source reported it and its live feed delivered since, so nothing reports until the track’s feed is live. A largest past the cap or below the floor reports nothing: the cache does not stand in for it, so a cap moved below the largest stays pending. Moving the bounds wakes a parked poll, which reports the largest once it is within them and newer than the last report.

Awaits poll_largest.

Source

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

The newest group: fetched once Self::poll_largest names it, so one already evicted is retrieved from upstream. None when the track ends before any group. Keep this subscriber while reading the group, which carries no demand of its own: dropped, the feed may end before the group’s last frames arrive.

Source

pub fn refresh(&self) -> Refreshing ⓘ

Ask the publisher for a group starting after the newest one this node holds, judged by the track’s Refresh, resolving once the request is sent.

The request is made now. It is sent once the newest group is old enough, when whatever serves this node’s copy reads it: the session forwarding it upstream, or a local publisher waiting in Demand::poll_refresh. Concurrent requests coalesce into one, and all of them resolve when it is sent. Dropping the future before then withdraws this caller’s request; one already sent stays sent. It resolves at once when there is nothing to send: a track that does not refresh, a ratio the newest group is under, a track with no group yet (whose first is already asked for), or a request already sent. It also resolves when a newer group lands first, which answers it. It errors if the track closes before then. A front’s reader asks the copy serving it, and asks the next one if that copy closes first.

The answer arrives like any other group: the first group this subscriber receives that starts after the newest held when it was called. A group already on its way when the request reached the publisher answers it, so across hops “made after this call” is best effort; a reader that needs that puts its own marker in the frame.

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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