gossamer/stream/writable_stream
The sink side of the Streams API. Build one from an underlying
sink via the Builder and write into it through a
Writer acquired with
get_writer.
Types
The configuration for a WritableStream.
pub opaque type Builder(a)
A JavaScript WritableStream — a destination for writing bytes or
objects.
See WritableStream on MDN.
pub type WritableStream(a)
Values
pub fn abort(
stream: WritableStream(a),
reason reason: r,
) -> promise.Promise(Result(Nil, stream.StreamLifecycleError))
Aborts the stream. Returns Locked if the stream is locked to a
writer, or Errored if the underlying sink’s abort callback throws
or returns a rejecting promise.
pub fn build(
builder: Builder(a),
) -> Result(WritableStream(a), stream.StreamLifecycleError)
Creates a WritableStream from the configured Builder. Returns
Errored if the start callback throws synchronously; the thrown
value is the variant’s reason.
pub fn close(
stream: WritableStream(a),
) -> promise.Promise(Result(Nil, stream.StreamLifecycleError))
Closes the stream after all writes complete. Returns Locked if
the stream is locked to a writer, or Errored if the underlying
sink’s close callback throws or returns a rejecting promise, or if
the stream is already closing or closed.
pub fn from_write(
write: fn(a, default_controller.DefaultController) -> b,
) -> WritableStream(a)
Creates a WritableStream from only a write callback — use when
the sink just needs to handle incoming chunks. If the callback
returns a Promise, the stream waits for it before accepting the
next chunk.
pub fn get_writer(
stream: WritableStream(a),
) -> Result(writer.Writer(a), stream.StreamLifecycleError)
Acquires a Writer that locks the stream. Returns Locked if the
stream is already locked.
pub fn is_locked(stream: WritableStream(a)) -> Bool
Checks whether the stream is locked to a writer.
pub fn with_abort(
builder: Builder(a),
abort: fn(dynamic.Dynamic) -> b,
) -> Builder(a)
Registers the abort callback that runs if the stream is aborted.
Receives the abort reason. If the callback returns a Promise, the
stream waits for it before resolving the abort.
pub fn with_close(
builder: Builder(a),
close: fn() -> b,
) -> Builder(a)
Registers the close callback that runs once after all writes
complete. If the callback returns a Promise, the stream waits for
it before resolving the close.
pub fn with_queuing_strategy(
builder: Builder(a),
strategy: stream.QueuingStrategy,
) -> Builder(a)
Sets the queuing strategy controlling backpressure on the stream’s
internal queue. Without this, the stream uses the default strategy
(chunk count, high water mark of 1).
pub fn with_start(
builder: Builder(a),
start: fn(default_controller.DefaultController) -> b,
) -> Builder(a)
Registers the start callback that runs once at construction. Use
to acquire resources or set up state. If the callback returns a
Promise, the stream waits for it to resolve before accepting
writes.
pub fn with_write(
builder: Builder(a),
write: fn(a, default_controller.DefaultController) -> b,
) -> Builder(a)
Registers the write callback that runs for each chunk written to
the sink. If the callback returns a Promise, the stream waits for
it before accepting the next chunk.