pub struct Stream<T> { /* private fields */ }Expand description
Defines a typed best-effort resumable message Stream owned by one Flow type.
Register the same definition in exactly one crate::PersistenceSchema. Clones share
identity and may be used at Client and Step call sites.
T implements Value when messages are written or read. Prefer a module-level
std::sync::LazyLock definition. Capacity is a shared approximate retention budget across
executions of the Flow type, not a maximum message size. Old messages can be trimmed.
Streams are progress output, not durable proof that an application mutation committed.
The shared budget covers one Flow type and Stream name across all Flow IDs. Background
trimming removes oldest messages. At capacity a Client write can return ResourceExhausted;
a message larger than the capacity can never fit and must not be retried unchanged.
Step writes also heartbeat without clearing the last checkpoint. They can be observed before
the handler finishes and can repeat after retry or replay. Client reads use opaque resume
tokens; pass each token unchanged. Use crate::Client::read_stream_with_timeout for forward
long polling and crate::Client::list_stream_messages for newest-first retained pages.
use dex_sdk::{Context, HandlerResult, Stream};
use std::sync::LazyLock;
static PROGRESS: LazyLock<Stream<String>> =
LazyLock::new(|| Stream::new("progress", 1024 * 1024));
fn report_progress(context: &mut Context) -> HandlerResult<()> {
let writer = PROGRESS.buffered_text(context)?;
writer.write("Processing started")?;
writer.write("Processing finished")?;
Ok(())
}Implementations§
Source§impl<T> Stream<T>
impl<T> Stream<T>
Sourcepub fn new(name: impl Into<String>, stream_capacity_bytes: i64) -> Self
pub fn new(name: impl Into<String>, stream_capacity_bytes: i64) -> Self
Creates a Stream with a positive approximate budget shared by all instances of its Flow.
§Panics
Panics when name is empty or stream_capacity_bytes is not positive.
Sourcepub fn stream_capacity_bytes(&self) -> i64
pub fn stream_capacity_bytes(&self) -> i64
Returns the approximate shared byte budget.
Sourcepub fn write(&self, context: &mut Context, value: T) -> HandlerResult<()>where
T: Value,
pub fn write(&self, context: &mut Context, value: T) -> HandlerResult<()>where
T: Value,
Appends one message immediately from the current Step execution.
§Errors
Returns crate::HandlerError for RPC or Flow timeout Contexts, unregistered Streams,
encoding failures, cancellation, or a closed Worker output stream. Dex storage failures are
not acknowledged.
Source§impl Stream<String>
impl Stream<String>
Sourcepub fn buffered_text(
&self,
context: &mut Context,
) -> HandlerResult<BufferedTextStream>
pub fn buffered_text( &self, context: &mut Context, ) -> HandlerResult<BufferedTextStream>
Creates an invocation-managed writer with a one-second interval and 16 KiB threshold.
The Worker flushes remaining text before the handler result or error. The writer preserves
chunks exactly, ignores empty chunks, and never splits a chunk.
An empty buffer does not heartbeat. Retry does not restore unsent text and can repeat
batches already sent. The threshold is soft: one large chunk can exceed it.
See Stream for an example; the invocation owns final flushing.
§Errors
Returns HandlerError unless this registered String Stream is used by an active Step.
Sourcepub fn buffered_text_with_options(
&self,
context: &mut Context,
options: BufferedTextStreamOptions,
) -> HandlerResult<BufferedTextStream>
pub fn buffered_text_with_options( &self, context: &mut Context, options: BufferedTextStreamOptions, ) -> HandlerResult<BufferedTextStream>
Creates an invocation-managed writer with explicit buffering settings.
§Errors
Returns HandlerError for invalid settings, an unregistered Stream, cancellation, or a
Context that does not belong to a Step.
Trait Implementations§
Auto Trait Implementations§
impl<T> Forget for Stream<T>
impl<T> Freeze for Stream<T>
impl<T> RefUnwindSafe for Stream<T>
impl<T> Send for Stream<T>
impl<T> Sync for Stream<T>
impl<T> Unpin for Stream<T>
impl<T> UnsafeUnpin for Stream<T>
impl<T> UnwindSafe for Stream<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request