pub struct StreamValue { /* private fields */ }Expand description
The runtime-visible stream value: metadata plus a live spine.
A StreamValue is the homogeneous stream object the runtime passes around.
It is a non-citizen live handle (it is not serialized directly; consumers
reconstruct the stream/Packet and stream/Metadata descriptors and
realize them separately). Build a finite, replayable stream with
StreamValue::pull or a producer-fed stream with StreamValue::push,
then drive it through the base combinators (next_packet, peek_packet,
take_packets, run_events, cancel, is_done).
As a kernel Object it presents as a Sequence, so it interoperates
with sequence-consuming operations directly.
Implementations§
Source§impl StreamValue
impl StreamValue
Sourcepub fn pull(metadata: StreamMetadata, items: Vec<StreamItem>) -> Self
pub fn pull(metadata: StreamMetadata, items: Vec<StreamItem>) -> Self
Builds a pull stream that yields the given pre-built items in order.
A pull stream is finite and self-draining: it serves items until
exhausted, then reports done. It rejects pushed packets.
Sourcepub fn push(metadata: StreamMetadata) -> Self
pub fn push(metadata: StreamMetadata) -> Self
Builds a push stream fed by an external producer.
The stream starts empty; producers call StreamValue::push_packet to
enqueue items under the buffer policy carried by metadata, and
consumers pull them out.
Sourcepub fn metadata(&self) -> &StreamMetadata
pub fn metadata(&self) -> &StreamMetadata
Returns the stream’s immutable metadata.
Sourcepub fn publish_claims(&self, cx: &mut Cx, subject: Ref) -> Result<()>
pub fn publish_claims(&self, cx: &mut Cx, subject: Ref) -> Result<()>
Publishes this stream’s metadata as claims about subject into cx.
Sourcepub fn push_packet(&self, item: StreamItem) -> Result<PushResult>
pub fn push_packet(&self, item: StreamItem) -> Result<PushResult>
Pushes a packet into a push stream, returning the backpressure outcome.
Returns an error when called on a pull stream, which accepts no input.
Sourcepub fn close_push(&self) -> Result<()>
pub fn close_push(&self) -> Result<()>
Closes the stream to further input, leaving buffered items to drain.
Sourcepub fn next_packet(&self) -> Result<Option<StreamItem>>
pub fn next_packet(&self) -> Result<Option<StreamItem>>
Pulls the next packet, or None if the stream is currently empty or
exhausted.
Does not block; on a push stream an empty-but-open queue yields None.
Sourcepub fn next_packet_timeout(
&self,
timeout: Duration,
) -> Result<Option<StreamItem>>
pub fn next_packet_timeout( &self, timeout: Duration, ) -> Result<Option<StreamItem>>
Pulls the next packet, blocking up to timeout for one to arrive.
On a pull stream this is equivalent to StreamValue::next_packet; on a
push stream it waits for a producer up to timeout before yielding
None.
Sourcepub fn peek_packet(&self) -> Result<Option<StreamItem>>
pub fn peek_packet(&self) -> Result<Option<StreamItem>>
Returns a clone of the next packet without consuming it.
Sourcepub fn is_done(&self) -> Result<bool>
pub fn is_done(&self) -> Result<bool>
Reports whether the stream is exhausted and will yield no more packets.
Sourcepub fn take_packets(&self, limit: usize) -> Result<Vec<StreamItem>>
pub fn take_packets(&self, limit: usize) -> Result<Vec<StreamItem>>
Pulls up to limit packets, stopping early when the stream runs dry.
Sourcepub fn run_events(
&self,
cx: &mut Cx,
run: Ref,
start_seq: u64,
) -> Result<Vec<Event>>
pub fn run_events( &self, cx: &mut Cx, run: Ref, start_seq: u64, ) -> Result<Vec<Event>>
Drains the stream into a vector of sequenced packet events.
Pulls every currently available packet, emitting one packet Event per
item numbered from start_seq, and appends a terminal done event if
the stream is exhausted. Events are attributed to run.
Sourcepub fn cancel(&self) -> Result<()>
pub fn cancel(&self) -> Result<()>
Cancels the stream: closes it and discards any buffered packets.
Sourcepub fn stats(&self) -> Result<StreamStats>
pub fn stats(&self) -> Result<StreamStats>
Returns a snapshot of the stream’s lifetime StreamStats.
Sourcepub fn queue_depth(&self) -> Result<usize>
pub fn queue_depth(&self) -> Result<usize>
Returns the number of packets currently buffered in the spine.
Sourcepub fn event_source(
self: &Arc<Self>,
run: Ref,
start_seq: u64,
) -> Arc<StreamEventSource>
pub fn event_source( self: &Arc<Self>, run: Ref, start_seq: u64, ) -> Arc<StreamEventSource>
Builds an StreamEventSource that feeds this stream’s packets into the
run ledger as sequenced events numbered from start_seq.
Trait Implementations§
Source§impl Object for StreamValue
impl Object for StreamValue
Source§fn display(&self, _cx: &mut Cx) -> Result<String>
fn display(&self, _cx: &mut Cx) -> Result<String>
Source§fn header(&self) -> &ObjectHeader
fn header(&self) -> &ObjectHeader
Source§fn op(&self, _key: &OpKey) -> Option<&dyn Op>
fn op(&self, _key: &OpKey) -> Option<&dyn Op>
key, if any.Source§impl ObjectCompat for StreamValue
impl ObjectCompat for StreamValue
Source§fn class(&self, cx: &mut Cx) -> Result<ClassRef>
fn class(&self, cx: &mut Cx) -> Result<ClassRef>
Source§fn as_sequence(&self) -> Option<&dyn Sequence>
fn as_sequence(&self) -> Option<&dyn Sequence>
Source§fn as_callable(&self) -> Option<&dyn Callable>
fn as_callable(&self) -> Option<&dyn Callable>
Source§fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>
fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>
Source§fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>
fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>
Source§fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>
fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>
Source§fn as_number_value(&self) -> Option<&dyn NumberValue>
fn as_number_value(&self) -> Option<&dyn NumberValue>
Source§fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>
fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>
Source§fn as_list(&self) -> Option<&(dyn ListValue + 'static)>
fn as_list(&self) -> Option<&(dyn ListValue + 'static)>
Source§fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>
fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>
Source§fn as_dir(&self) -> Option<&(dyn Dir + 'static)>
fn as_dir(&self) -> Option<&(dyn Dir + 'static)>
Source§fn as_expr(&self, cx: &mut Cx) -> Result<Expr, Error>
fn as_expr(&self, cx: &mut Cx) -> Result<Expr, Error>
Source§fn truth(&self, _cx: &mut Cx) -> Result<bool, Error>
fn truth(&self, _cx: &mut Cx) -> Result<bool, Error>
Source§impl Sequence for StreamValue
impl Sequence for StreamValue
Source§fn next_item(&self, cx: &mut Cx) -> Result<Option<SequenceItem>>
fn next_item(&self, cx: &mut Cx) -> Result<Option<SequenceItem>>
Ok(None) once exhausted.