-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Document highWaterMark option of events.on() #52078
Copy link
Copy link
Closed
Labels
eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.streamIssues and PRs related to the stream subsystem.Issues and PRs related to the stream subsystem.
Metadata
Metadata
Assignees
Labels
eventsIssues and PRs related to the events subsystem / EventEmitter.Issues and PRs related to the events subsystem / EventEmitter.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.streamIssues and PRs related to the stream subsystem.Issues and PRs related to the stream subsystem.
What is the problem this feature will solve?
#41276 added the
highWaterMarkoption toevents.on()in Node 20.0.0.node/lib/events.js
Line 1067 in 1abff07
That option is quite useful when using
on(stream, 'data').on()uses an internal buffer. If too many events happen at once, this buffer can potentially consume lots of memory. When thehighWaterMarkoption is used, the stream is temporarily paused when this happens. Once the buffer is empty, the stream is resumed. Basically, this makeson()stream-friendly.What is the feature you are proposing to solve the problem?
Document the
highWaterMarkoption ofstream.on().What alternatives have you considered?
An alternative would be, if a
ReadableorDuplexis passed toon(), to set thehighWaterMarkoption tostream.readableHighWaterMark. This would enable the above streaming behavior by default, when a stream is used.In many cases, users will just want to enable this feature and use the same
highWaterMarkas the stream. So enabling this by default for stream might remove the need to expose the option.