Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions doc/api/webstreams.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,39 @@ async function* asyncIterableGenerator() {
})();
```

To pipe the resulting {ReadableStream} into a {WritableStream} the {Iterable}
should yield a sequence of {Buffer}, {TypedArray}, or {DataView} objects.

```mjs
import { ReadableStream } from 'node:stream/web';
import { Buffer } from 'node:buffer';

async function* asyncIterableGenerator() {
yield Buffer.from('a');
yield Buffer.from('b');
yield Buffer.from('c');
}

const stream = ReadableStream.from(asyncIterableGenerator());

stream.pipeTo(createWritableStreamSomehow());
```

```cjs
const { ReadableStream } = require('node:stream/web');
const { Buffer } = require('node:buffer');

async function* asyncIterableGenerator() {
yield Buffer.from('a');
yield Buffer.from('b');
yield Buffer.from('c');
}

const stream = ReadableStream.from(asyncIterableGenerator());

stream.pipeTo(createWritableStreamSomehow());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this promise is not awaited, then something else needs to make sure there is enough i/o scheduled on the event loop to ensure the process does not close before the pipe completes.
 

Suggested change
stream.pipeTo(createWritableStreamSomehow());
stream.pipeTo(createWritableStreamSomehow());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell I put this in an async IIFE and awaited the promise.

```

### Class: `ReadableStreamDefaultReader`

<!-- YAML
Expand Down
Loading