@@ -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
302309The ` 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
306324All 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