Skip to main content

OpenStreamWriter

Struct OpenStreamWriter 

Source
pub struct OpenStreamWriter { /* private fields */ }
Expand description

Minimal CEP-41 producer/writer.

Implementations§

Source§

impl OpenStreamWriter

Source

pub fn new(options: OpenStreamWriterOptions) -> Self

Create a new writer from explicit options.

Source

pub fn progress_token(&self) -> &str

The stream id (stringified progressToken).

Source

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.

Source

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).

Source

pub async fn start(&self) -> Result<()>

Explicitly publish the start frame (idempotent; lazy on first write).

Source

pub async fn write(&self, data: String) -> Result<()>

Publish one ordered chunk frame, starting the stream lazily.

Source

pub async fn ping(&self) -> Result<()>

Publish a keepalive ping carrying a fresh {token}:{n} nonce.

Source

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.

Source

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).

Source

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).

Source

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.

Source

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).

Source

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.

Source

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

Source§

fn clone(&self) -> OpenStreamWriter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more