@@ -257,6 +257,11 @@ changes:
257
257
- v18.14.0
258
258
pr-url: https://github.com/nodejs/node/pull/46205
259
259
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.
260
265
-->
261
266
262
267
* ` stream ` {Stream|ReadableStream|WritableStream} A readable and/or writable
@@ -265,7 +270,9 @@ changes:
265
270
* ` error ` {boolean|undefined}
266
271
* ` readable ` {boolean|undefined}
267
272
* ` 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 ` .
269
276
* Returns: {Promise} Fulfills when the stream is no
270
277
longer readable or writable.
271
278
@@ -301,6 +308,17 @@ rs.resume(); // Drain the stream.
301
308
302
309
The ` finished ` API also provides a [ callback version] [ stream-finished ] .
303
310
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
+
304
322
### Object mode
305
323
306
324
All streams created by Node.js APIs operate exclusively on strings, {Buffer},
@@ -2744,8 +2762,6 @@ changes:
2744
2762
underlying stream will _ not_ be aborted if the signal is aborted. The
2745
2763
callback will get called with an ` AbortError ` . All registered
2746
2764
listeners added by this function will also be removed.
2747
- * ` cleanup ` {boolean} remove all registered stream listeners.
2748
- ** Default:** ` false ` .
2749
2765
* ` callback ` {Function} A callback function that takes an optional error
2750
2766
argument.
2751
2767
* Returns: {Function} A cleanup function which removes all registered
0 commit comments