Skip to main content

Consumer

Struct Consumer 

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

Consume a group, frame-by-frame.

Implementations§

Source§

impl Consumer

Source

pub fn keep_alive(&self)

Mark the group as still being read, so a slow drain doesn’t expire it.

Self::read_frames stamps the group’s cache access once per batch, which bounds frames rather than elapsed time. A reader that takes longer than the track’s latency_max to work through one batch (a publisher writing to a flow-controlled peer, say) calls this between frames, or the rest of the group is expired out from under it mid-serve. Self::read_frame stamps on every call and needs no help.

Cheap and idempotent within a coarse clock tick, so calling it per frame is fine.

Source

pub fn timescale(&self) -> Timescale

The parent track’s timescale.

Source

pub fn frame_count(&self) -> usize

The number of frames written so far (completed plus any in-flight), independent of how many this consumer has read. The final total once the group is finished.

Source

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

Advance the read cursor to sequence, skipping every frame below it.

Skipped frames are never returned, and an eviction confined to them is not a gap: reads resume at the cursor instead of failing with Error::Lagged. An eviction at or above the cursor still fails, because the caller asked for that frame. The cursor only moves forward; a sequence at or below it is a no-op.

Source

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

Return a consumer for the next frame for chunked reading.

Source

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

Poll for the next frame, without blocking.

Returns None if the group is finished and the index is out of range.

Source

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

Read the next frame (timestamp and payload) all at once, without blocking.

Use Self::read_frames to pull a whole batch under one lock; a group of small frames drains several times faster that way.

Source

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

Read the next frame (timestamp and payload) all at once.

Source

pub fn poll_read_frames<const N: usize>( &mut self, waiter: &Waiter, out: &mut Buffer<N>, ) -> Poll<Result<usize>>

Fill out with every frame that is ready, up to its capacity, without blocking.

Returns how many frames were written; they’re in frame::Buffer::filled. The buffer’s previous batch is dropped first, so one buffer serves a whole group.

This is a short read: it returns as soon as anything is ready rather than waiting for out to fill, so a partial batch does not mean the group ended. Only a count of 0 does (and only for a non-zero capacity).

One stamp covers the whole batch, so a slow drain calls Self::keep_alive between frames.

Source

pub async fn read_frames<'a, const N: usize>( &mut self, out: &'a mut Buffer<N>, ) -> Result<&'a mut [Frame]>

Fill out with every frame that is ready, blocking until at least one is or the group ends. Returns the batch, empty only at the end of the group.

See Self::poll_read_frames for the short-read semantics.

Source

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

Poll until the group terminates, returning this cursor’s next frame index.

Source

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

Block until the group terminates, returning this cursor’s next frame index.

This answers for the cursor, not the group: a reader that drained every frame gets the clean end even if the group was aborted afterwards to release its cache, while one that stopped short gets that abort. A prior Self::skip_to contributes to the index even though those frames were not read. Use Self::frame_count for the producer’s total.

Trait Implementations§

Source§

impl Clone for Consumer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Deref for Consumer

Source§

type Target = Info

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> MaybeSend for T
where T: Send + ?Sized,

Source§

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

Source§

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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