pub struct BoundedAsyncStream<T> { /* private fields */ }Expand description
A bounded, lossy-by-default, executor-agnostic async stream.
Items are pushed by one or more AsyncStreamSender handles and pulled
asynchronously via BoundedAsyncStream::next.
See the module-level docs for the full design rationale.
Implementations§
Source§impl<T> BoundedAsyncStream<T>
impl<T> BoundedAsyncStream<T>
Sourcepub fn new(capacity: usize) -> (Self, AsyncStreamSender<T>)
pub fn new(capacity: usize) -> (Self, AsyncStreamSender<T>)
Creates a new bounded stream with the given capacity.
Returns the consumer side and a single producer; clone the sender to fan out to multiple producers.
§Panics
Panics if capacity is 0 — a zero-capacity buffer would drop every
item before the consumer could observe it. Use capacity 1 if you
genuinely want “latest only” semantics.
Sourcepub const fn next(&self) -> NextItem<'_, T> ⓘ
pub const fn next(&self) -> NextItem<'_, T> ⓘ
Returns a future that resolves to the next item, or None once the
stream is closed and drained.
Sourcepub fn try_next(&self) -> Option<T>
pub fn try_next(&self) -> Option<T>
Non-blocking pop. Returns None if the buffer is empty (regardless
of whether the stream is open or closed).
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns true if the stream has been closed (all senders dropped).
Note: a closed stream may still have buffered items to drain.
Sourcepub fn buffered_count(&self) -> usize
pub fn buffered_count(&self) -> usize
Returns the number of items currently buffered (0..=capacity).
Sourcepub fn clear_buffer(&self)
pub fn clear_buffer(&self)
Drops all currently buffered items without closing the stream.
Trait Implementations§
Source§impl<T> Debug for BoundedAsyncStream<T>
impl<T> Debug for BoundedAsyncStream<T>
Source§impl<T> Drop for BoundedAsyncStream<T>
impl<T> Drop for BoundedAsyncStream<T>
Source§impl<T: 'static> Stream for BoundedAsyncStream<T>
Available on crate feature futures-stream only.
impl<T: 'static> Stream for BoundedAsyncStream<T>
futures-stream only.