GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: fix stream async iterator sample · nodejs/node@d51de78

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • stream.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/stream.md‎

Copy file name to clipboardExpand all lines: doc/api/stream.md
+11-3Lines changed: 11 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2644,15 +2644,23 @@ const finished = util.promisify(stream.finished);
26442644

26452645
const writable = fs.createWriteStream('./file');
26462646

2647-
(async function() {
2647+
async function pump(iterator, writable) {
26482648
for await (const chunk of iterator) {
26492649
// Handle backpressure on write().
2650-
if (!writable.write(chunk))
2650+
if (!writable.write(chunk)) {
2651+
if (writable.destroyed) return;
26512652
await once(writable, 'drain');
2653+
}
26522654
}
26532655
writable.end();
2656+
}
2657+
2658+
(async function() {
26542659
// Ensure completion without errors.
2655-
await finished(writable);
2660+
await Promise.all([
2661+
pump(iterator, writable),
2662+
finished(writable)
2663+
]);
26562664
})();
26572665
```
26582666

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.