docs: writable streams from async iterators example issue #31222
Closed
Description
Given the example from https://nodejs.org/api/stream.html#stream_piping_to_writable_streams_from_async_iterators.
There is a problem where this can cause an unhandled exception if the writable
emits an 'error'
before the first chunk arrives from the iterator
, e.g. if writable
is a fs
stream and it fails while opening the file.
const writable = fs.createWriteStream('./file');
for await (const chunk of iterator) {
// Handle backpressure on write().
if (!writable.write(chunk))
await once(writable, 'drain');
}
writable.end();
// Ensure completion without errors.
await finished(writable);
Metadata
Assignees
Labels
No labels
Activity