Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: muxed streams as web streams #1847

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Commits on Jun 23, 2023

  1. feat!: muxed streams as web streams

    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
    achingbrain committed Jun 23, 2023
    Configuration menu
    Copy the full SHA
    96187aa View commit details
    Browse the repository at this point in the history
  2. chore: fix build

    achingbrain committed Jun 23, 2023
    Configuration menu
    Copy the full SHA
    29f1758 View commit details
    Browse the repository at this point in the history
  3. chore: fix import

    achingbrain committed Jun 23, 2023
    Configuration menu
    Copy the full SHA
    e7d1dd7 View commit details
    Browse the repository at this point in the history