Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 73b05cf

Browse filesBrowse files
Renegade334targos
authored andcommitted
doc: correct cleanup option in stream.(promises.)finished
PR-URL: #55043 Refs: #44862 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 36c9ea8 commit 73b05cf
Copy full SHA for 73b05cf

File tree

Expand file treeCollapse file tree

1 file changed

+19
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-3
lines changed
Open diff view settings
Collapse file

‎doc/api/stream.md‎

Copy file name to clipboardExpand all lines: doc/api/stream.md
+19-3Lines changed: 19 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ changes:
257257
- v18.14.0
258258
pr-url: https://github.com/nodejs/node/pull/46205
259259
description: Added support for `ReadableStream` and `WritableStream`.
260+
- version:
261+
- v19.1.0
262+
- v18.13.0
263+
pr-url: https://github.com/nodejs/node/pull/44862
264+
description: The `cleanup` option was added.
260265
-->
261266

262267
* `stream` {Stream|ReadableStream|WritableStream} A readable and/or writable
@@ -265,7 +270,9 @@ changes:
265270
* `error` {boolean|undefined}
266271
* `readable` {boolean|undefined}
267272
* `writable` {boolean|undefined}
268-
* `signal`: {AbortSignal|undefined}
273+
* `signal` {AbortSignal|undefined}
274+
* `cleanup` {boolean|undefined} If `true`, removes the listeners registered by
275+
this function before the promise is fulfilled. **Default:** `false`.
269276
* Returns: {Promise} Fulfills when the stream is no
270277
longer readable or writable.
271278

@@ -301,6 +308,17 @@ rs.resume(); // Drain the stream.
301308

302309
The `finished` API also provides a [callback version][stream-finished].
303310

311+
`stream.finished()` leaves dangling event listeners (in particular
312+
`'error'`, `'end'`, `'finish'` and `'close'`) after the returned promise is
313+
resolved or rejected. The reason for this is so that unexpected `'error'`
314+
events (due to incorrect stream implementations) do not cause unexpected
315+
crashes. If this is unwanted behavior then `options.cleanup` should be set to
316+
`true`:
317+
318+
```js
319+
await finished(rs, { cleanup: true });
320+
```
321+
304322
### Object mode
305323

306324
All streams created by Node.js APIs operate exclusively on strings, {Buffer},
@@ -2744,8 +2762,6 @@ changes:
27442762
underlying stream will _not_ be aborted if the signal is aborted. The
27452763
callback will get called with an `AbortError`. All registered
27462764
listeners added by this function will also be removed.
2747-
* `cleanup` {boolean} remove all registered stream listeners.
2748-
**Default:** `false`.
27492765
* `callback` {Function} A callback function that takes an optional error
27502766
argument.
27512767
* Returns: {Function} A cleanup function which removes all registered

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.