You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactors streams from duplex async iterables:
```js
{
source: Duplex<AsyncGenerator<Uint8Array, void, unknown>, Source<Uint8Array | Uint8ArrayList>, Promise<void>
sink: (Source<Uint8Array | Uint8ArrayList>) => Promise<void>
}
```
to `ReadableWriteablePair<Uint8Array>`s:
```js
{
readable: ReadableStream<Uint8Array>
writable: WritableStream<Uint8Array>
}
```
Since the close methods for web streams are asynchronous, this lets
us close streams cleanly - that is, wait for any buffered data to
be sent/consumed before closing the stream.
We still need to be able abort a stream in an emergency, so streams
have the following methods for graceful closing:
```js
stream.readable.cancel(reason?: any): Promise<void>
stream.writable.close(): Promise<void>
// or
stream.close(): Promise<void>
```
..and for emergency closing:
```js
stream.abort(err: Error): void
```
Connections and multiaddr connections have the same `close`/`abort`
semantics, but are still Duplexes since making them web streams
would mean we need to convert things like node streams (for tcp) to
web streams which would just make things slower.
Transports such as WebTransport and WebRTC already deal in web
streams when multiplexing so these no longer need to be converted to
Duplex streams so it's win-win.
Fixes#1793
0 commit comments