Description
What is the problem this feature will solve?
Right now, there is no stable way to change the maxEventTargetListeners
of an AbortSignal
without importing from node:events
.
This makes it impossible to write isomorphic library code that adds more than the default 10 event listeners, without having to resort to workarounds such as
/**
* A workaround to set the `maxListeners` property of a node EventEmitter without having to import
* the `node:events` module, which would make the code non-portable.
*/
function setMaxListeners(maxListeners: number, emitter: any) {
const key = Object.getOwnPropertySymbols(new AbortController().signal).find(
(key) => key.description === "events.maxEventTargetListeners"
);
if (key) emitter[key] = maxListeners;
}
This relies on the events.maxEventTargetListeners
symbol description, which, to my knowledge is not part of any public API and could change at any time.
What is the feature you are proposing to solve the problem?
Add a AbortSignal.setMaxListeners
instance method so isomorphic code could do something like
if ('setMaxListeners' in signal) signal.setMaxListeners(20)
What alternatives have you considered?
Alternatively, if this is not an option as it could pollute a spec-defined object with additional properties, use Symbol.for
instead of new Symbol
for kMaxEventTargetListeners
and make that a part of the official api.
I would be willing to implement this feature.
Metadata
Metadata
Assignees
Type
Projects
Status