pub struct Consumer { /* private fields */ }Expand description
Consume a group, frame-by-frame.
Usually a view of one Producer, but a group served across a route change is
spliced: it reads each contributing route’s copy in turn, joined at the frame the
takeover happened on, so the reader never sees the seam.
Implementations§
Source§impl Consumer
impl Consumer
Sourcepub fn keep_alive(&self)
pub fn keep_alive(&self)
Mark the group as still being read, so a slow batch drain does not expire it.
Sourcepub fn index(&self) -> u64
pub fn index(&self) -> u64
The index of the next frame this consumer will return.
Starts at 0, or at the group’s first available frame once Self::set_frames has
clamped it, and advances by one per frame read.
Sourcepub fn set_frames(&mut self, frames: impl RangeBounds<u64>)
pub fn set_frames(&mut self, frames: impl RangeBounds<u64>)
Limit subsequent reads to these frame indices without rewinding read progress.
2..=5 includes frames 2 through 5; 2..5 excludes frame 5. An omitted
start preserves read progress, and an omitted end removes the cap.
Raising the cap makes unread cached frames available again.
Sourcepub fn skip_to(&mut self, index: u64)
pub fn skip_to(&mut self, index: u64)
Advance the read cursor to index, skipping every frame below it.
Unlike Self::set_frames, this does not clamp past a requested frame the group
never held. A Producer::start_at floor above index still surfaces as
Error::Lagged.
Sourcepub fn frame_count(&self) -> usize
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.
Sourcepub async fn next_frame(&mut self) -> Result<Option<Consumer>>
pub async fn next_frame(&mut self) -> Result<Option<Consumer>>
Return a consumer for the next frame for chunked reading.
Sourcepub fn poll_next_frame(
&mut self,
waiter: &Waiter,
) -> Poll<Result<Option<Consumer>>>
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, or the cursor
passed the Self::set_frames cap.
Sourcepub fn poll_read_frame(
&mut self,
waiter: &Waiter,
) -> Poll<Result<Option<Frame>>>
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.
Sourcepub async fn read_frame(&mut self) -> Result<Option<Frame>>
pub async fn read_frame(&mut self) -> Result<Option<Frame>>
Read the next frame (timestamp and payload) all at once.
Sourcepub fn poll_read_frames<const N: usize>(
&mut self,
waiter: &Waiter,
out: &mut Buffer<N>,
) -> Poll<Result<usize>>
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.
This is a short read: it returns as soon as anything is ready rather than
waiting for out to fill. A zero count means the group ended when the buffer
has non-zero capacity.
Sourcepub async fn read_frames<'a, const N: usize>(
&mut self,
out: &'a mut Buffer<N>,
) -> Result<&'a mut [Frame]>
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 a frame arrives or
the group ends. Returns the current batch, empty only at the end of the group.
Sourcepub fn poll_finished(&mut self, waiter: &Waiter) -> Poll<Result<u64>>
pub fn poll_finished(&mut self, waiter: &Waiter) -> Poll<Result<u64>>
Poll until the group terminates, returning this cursor’s next frame index.
Sourcepub async fn finished(&mut self) -> Result<u64>
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.