pub struct OpenStreamWriter { /* private fields */ }Expand description
Minimal CEP-41 producer/writer.
Implementations§
Source§impl OpenStreamWriter
impl OpenStreamWriter
Sourcepub fn new(options: OpenStreamWriterOptions) -> Self
pub fn new(options: OpenStreamWriterOptions) -> Self
Create a new writer from explicit options.
Sourcepub fn progress_token(&self) -> &str
pub fn progress_token(&self) -> &str
The stream id (stringified progressToken).
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Whether the writer is still live (not yet closed/aborted).
true for any freshly-created writer; see has_started.
Sourcepub fn has_started(&self) -> bool
pub fn has_started(&self) -> bool
Whether the writer has begun streaming by publishing its start frame.
Distinct from is_active: used to tell apart writers a
tool actually streams through from ones created only because the request
carried a progress token (the response-deferral guard).
Sourcepub async fn start(&self) -> Result<()>
pub async fn start(&self) -> Result<()>
Explicitly publish the start frame (idempotent; lazy on first write).
Sourcepub async fn write(&self, data: String) -> Result<()>
pub async fn write(&self, data: String) -> Result<()>
Publish one ordered chunk frame, starting the stream lazily.
Sourcepub async fn ping(&self) -> Result<()>
pub async fn ping(&self) -> Result<()>
Publish a keepalive ping carrying a fresh {token}:{n} nonce.
Sourcepub async fn pong(&self, nonce: String) -> Result<()>
pub async fn pong(&self, nonce: String) -> Result<()>
Publish a pong echoing the peer’s ping nonce.
An inbound ping is proof of peer liveness (CEP-41: receipt of any valid
frame resets the idle window), so this refreshes the keepalive clock
before responding.
Sourcepub fn tick(&self, now: Instant) -> KeepaliveAction
pub fn tick(&self, now: Instant) -> KeepaliveAction
Pure keepalive transition (idle → ping, probe deadline → abort), mirroring
the reader-side
OpenStreamSession::tick.
Driven by the owning transport’s periodic sweep with Instant::now().
Returns KeepaliveAction::None when keepalive is disabled, the writer is
inactive, or it has not yet started (the idle window arms at start).
Sourcepub async fn send_probe(&self, nonce: String) -> Result<()>
pub async fn send_probe(&self, nonce: String) -> Result<()>
Publish a keepalive ping carrying a nonce already minted by tick.
Used by the transport sweep; unlike ping it does not mint a
new nonce (the probe recorded by tick must match the frame on the wire so
a matching pong clears it). Does not take the op lock, so a stuck app
write cannot block keepalive (mirroring the TS writer’s queue bypass).
Ceiling: by skipping the op lock, this probe’s progress (shared atomic)
can interleave with an in-flight write — a probe may carry a lower
progress than a chunk published just before it. Harmless: relays reorder
regardless and control frames aren’t chunkIndex-gap-checked. Re-serialize
under the op lock only if strict monotonic publish-order is ever required
(which would re-block keepalive behind a stuck write).
Sourcepub fn ack_probe(&self, nonce: &str)
pub fn ack_probe(&self, nonce: &str)
Acknowledge an inbound pong matching the pending keepalive probe (CEP-41).
A matching pong clears the probe and refreshes the idle window. A pong
whose nonce does not match the pending probe is not evidence of
liveness (CEP-41: “A pong with an unknown … nonce MUST NOT be treated as
evidence of liveness”) and is ignored.
Sourcepub fn dispose(&self)
pub fn dispose(&self)
Release writer resources without publishing a terminal frame — used on transport teardown so the writer no longer drives keepalive. Idempotent.
Only flips active to false: tick and
ack_probe early-return on that flag, so an armed probe
becomes inert without needing to be cleared (matching close/abort,
which also leave keepalive state untouched once terminal).
Sourcepub async fn close(&self) -> Result<()>
pub async fn close(&self) -> Result<()>
Close the stream gracefully. Declares lastChunkIndex iff any chunks were
written. Runs on_close after the
frame is published (even on publish failure); propagates the publish error.
Sourcepub async fn abort(&self, reason: Option<String>) -> Result<()>
pub async fn abort(&self, reason: Option<String>) -> Result<()>
Abort the stream (terminal). Claims the terminal transition without the op
lock, so it never waits on a stuck write. Runs
on_abort after the frame is
published (even on publish failure); propagates the publish error.
Idempotent: a second abort (or one after close) is a no-op.
Trait Implementations§
Source§impl Clone for OpenStreamWriter
impl Clone for OpenStreamWriter
Source§fn clone(&self) -> OpenStreamWriter
fn clone(&self) -> OpenStreamWriter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for OpenStreamWriter
impl !UnwindSafe for OpenStreamWriter
impl Freeze for OpenStreamWriter
impl Send for OpenStreamWriter
impl Sync for OpenStreamWriter
impl Unpin for OpenStreamWriter
impl UnsafeUnpin for OpenStreamWriter
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more