diff --git a/doc/api/events.md b/doc/api/events.md index 872ebfd6179d4e..febe3adc63b070 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -1661,12 +1661,31 @@ console.log(listenerCount(myEmitter, 'event')); added: - v13.6.0 - v12.16.0 +changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/52080 + description: Support `highWaterMark` and `lowWaterMark` options, + For consistency. Old options are still supported. + - version: + - v20.0.0 + pr-url: https://github.com/nodejs/node/pull/41276 + description: The `close`, `highWatermark`, and `lowWatermark` + options are supported now. --> * `emitter` {EventEmitter} * `eventName` {string|symbol} The name of the event being listened for * `options` {Object} * `signal` {AbortSignal} Can be used to cancel awaiting events. + * `close` - {string\[]} Names of events that will end the iteration. + * `highWaterMark` - {integer} **Default:** `Number.MAX_SAFE_INTEGER` + The high watermark. The emitter is paused every time the size of events + being buffered is higher than it. Supported only on emitters implementing + `pause()` and `resume()` methods. + * `lowWaterMark` - {integer} **Default:** `1` + The low watermark. The emitter is resumed every time the size of events + being buffered is lower than it. Supported only on emitters implementing + `pause()` and `resume()` methods. * Returns: {AsyncIterator} that iterates `eventName` events emitted by the `emitter` ```mjs diff --git a/lib/events.js b/lib/events.js index 9bb22059c1fd9a..6501b003ae46dc 100644 --- a/lib/events.js +++ b/lib/events.js @@ -1053,8 +1053,8 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) { * @param {{ * signal: AbortSignal; * close?: string[]; - * highWatermark?: number, - * lowWatermark?: number + * highWaterMark?: number, + * lowWaterMark?: number * }} [options] * @returns {AsyncIterator} */ @@ -1065,10 +1065,12 @@ function on(emitter, event, options = kEmptyObject) { validateAbortSignal(signal, 'options.signal'); if (signal?.aborted) throw new AbortError(undefined, { cause: signal?.reason }); - const highWatermark = options.highWatermark ?? NumberMAX_SAFE_INTEGER; - validateInteger(highWatermark, 'options.highWatermark', 1); - const lowWatermark = options.lowWatermark ?? 1; - validateInteger(lowWatermark, 'options.lowWatermark', 1); + // Support both highWaterMark and highWatermark for backward compatibility + const highWatermark = options.highWaterMark ?? options.highWatermark ?? NumberMAX_SAFE_INTEGER; + validateInteger(highWatermark, 'options.highWaterMark', 1); + // Support both lowWaterMark and lowWatermark for backward compatibility + const lowWatermark = options.lowWaterMark ?? options.lowWatermark ?? 1; + validateInteger(lowWatermark, 'options.lowWaterMark', 1); // Preparing controlling queues and variables FixedQueue ??= require('internal/fixed_queue'); diff --git a/lib/internal/readline/interface.js b/lib/internal/readline/interface.js index e26fa6561e8679..8ae051e4eadbeb 100644 --- a/lib/internal/readline/interface.js +++ b/lib/internal/readline/interface.js @@ -1359,7 +1359,7 @@ class Interface extends InterfaceConstructor { this[kLineObjectStream] = EventEmitter.on( this, 'line', { close: ['close'], - highWatermark: 1024, + highWaterMark: 1024, [kFirstEventParam]: true, }); }