-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Expose setMaxListeners
property on AbortSignal
#54758
Comments
The right avenue to purse this change is WHATWG (the group maintaining those standards). From past experience, any time we deviate from the standard we cause more harm than good. |
But isn't So this would try to explore a way to get closer to the standard, not further away. |
By that logic, another alternative suggestion here could be: Alternative suggestion: set no default listener count limit on
|
@jasnell you added the warning in @KhafraDev you added those getters/setters in What do you folks think? |
node shouldn't have implemented warnings or interop with EventEmitter in the first place, but we absolutely shouldn't deviate further from the spec and other implementations |
@nodejs/web-standards what do you all think? |
Pinging @lucacasonato too (hope you don't mind). |
Agree with @KhafraDev. If anything this should be a setter function you import from |
I agree. We should not extend the standard API with non-standard extensions. |
+1 (no nonstandard extensions). I do like the alternative suggestion tho (#54758 (comment)) |
I agree with the alternative suggestion as well |
@jasnell are you ok for #54758 (comment)? |
Just so we're clear - we are within our rights from the spec's PoV to emit a warning on more than N listeners (or really anything, warnings aren't considered observable). We've clarified that several times with WHATWG explicitly to make sure. |
I actually prefer that warning remain in place as it has actually proved useful in a couple of cases. But I won't block removing it. |
You can also use import { setMaxListeners } from 'node:events'
setMaxListeners(10, new EventEmitter())
setMaxListeners(10, new BroadcastChannel())
setMaxListeners(10, new AbortSignal()) |
@kettanaito assuming I'm writing a package that will never run outside of node - which was the whole trigger for this issue - I'm not, and I was looking for an isomorphic way of doing this 😅 That said, this has been sitting for a while and I'm not sure what the conclusion really was - with support for both directions, there didn't seem to be a final verdict. Would you at this point accept a PR with my suggestion of setting Users in search of potential performance problems or memory leaks could still enable it, but it would probably reduce friction a lot for people who want to write isomorphic code. |
You can use the somewhat new
|
@KhafraDev this is something I could do as an end user, but as a library author I cannot advise all my users to turn off that warning - they might want to rely on it in different places, while not wanting to get warnings from dependency internals. As a library author I can also not depend on the default warning number being 10 and try to split up my 15 subscribers into e.g. 7 and 8 - the user could have changed their default to 5. The only viable options is that as a library author I
The ugly workaround I'm currently using is iterating |
What is the problem this feature will solve?
Right now, there is no stable way to change the
maxEventTargetListeners
of anAbortSignal
without importing fromnode: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
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 likeWhat 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 ofnew Symbol
forkMaxEventTargetListeners
and make that a part of the official api.I would be willing to implement this feature.
The text was updated successfully, but these errors were encountered: