diff --git a/imports.md b/imports.md index 1ae5b12..23ba901 100644 --- a/imports.md +++ b/imports.md @@ -132,12 +132,15 @@ use the subscribe function to obtain a po for using wasi:io/poll.

resource output-stream

An output bytestream.

-

output-streams are non-blocking to the extent practical on +

output-streams are non-blocking to the extent practical on underlying platforms. Except where specified otherwise, I/O operations also always return promptly, after the number of bytes that can be written promptly, which could even be zero. To wait for the stream to be ready to accept data, the subscribe function to obtain a pollable which can be -polled for using wasi:io/poll.

+polled for using wasi:io/poll.

+

Dropping an output-stream while there's still an active write in +progress may trap. Before dropping the stream, be sure to either fully +flush or cancel your writes.

Functions

[method]input-stream.read: func

Perform a non-blocking read from the stream.

@@ -418,3 +421,16 @@ is ready for reading, before performing the splice.

+

[method]output-stream.cancel: func

+

Initiate cancellation of any pending or in-progress writes. +This is an asynchronous operation. Use subscribe to wait for the +cancellation to finish. Dropping the stream while the cancellation +is in progress may trap.

+

While the cancellation is in progress, all other operations on this +stream respond as though the stream is currently not available for +I/O. (e.g. check-write returns 0). After cancellation has completed, +all operations return as though the stream is closed.

+
Params
+ diff --git a/wit/streams.wit b/wit/streams.wit index 6d2f871..399561d 100644 --- a/wit/streams.wit +++ b/wit/streams.wit @@ -102,6 +102,10 @@ interface streams { /// promptly, which could even be zero. To wait for the stream to be ready to /// accept data, the `subscribe` function to obtain a `pollable` which can be /// polled for using `wasi:io/poll`. + /// + /// Dropping an `output-stream` while there's still an active write in + /// progress may trap. Before dropping the stream, be sure to either fully + /// flush or cancel your writes. resource output-stream { /// Check readiness for writing. This function never blocks. /// @@ -258,5 +262,16 @@ interface streams { /// The number of bytes to splice len: u64, ) -> result; + + /// Initiate cancellation of any pending or in-progress writes. + /// This is an asynchronous operation. Use `subscribe` to wait for the + /// cancellation to finish. Dropping the stream while the cancellation + /// is in progress may trap. + /// + /// While the cancellation is in progress, all other operations on this + /// stream respond as though the stream is currently not available for + /// I/O. (e.g. `check-write` returns 0). After cancellation has completed, + /// all operations return as though the stream is closed. + cancel: func(); } }