Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: document missing options of events.on #52080

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -1661,12 +1661,31 @@
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

Check warning on line 1671 in doc/api/events.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
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`
atlowChemi marked this conversation as resolved.
Show resolved Hide resolved

```mjs
Expand Down
14 changes: 8 additions & 6 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ class Interface extends InterfaceConstructor {
this[kLineObjectStream] = EventEmitter.on(
this, 'line', {
close: ['close'],
highWatermark: 1024,
highWaterMark: 1024,
[kFirstEventParam]: true,
});
}
Expand Down