-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
events: add addDisposableListener method to EventEmitter #58453
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
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
Relevant to advancing on this: #58526 |
I'm ok with the addition. I'm a bit worried about the potential change in behavior, as I didn't have time to explore yet if there is a change in the order of operations. |
What change in behavior are you concerned about? This should not change any existing behavior of the |
718fe84
to
2657ecb
Compare
I've updated the implementation to rename the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with removal of obsolete no-undef
s and assuming consensus on this in #58526.
Perhaps using dispose === dispose[Symbol.dispose]
can be made into recommended pattern (whenever we don't have more meaningful return values) in the ERM guideline.
Is there any way we can avoid adding yet another way to register events? i.e. can this be an option and not a method? I think this was blocked previously in AbortSignal due to a V8 optimization that happened since. |
Not without adding too much complexity. As it is now, |
Regarding the single-use disposable that's just a disposer, with no associated object data: is function dispose() { ... }
dispose[SymbolDispose] = dispose
return dispose OK, or should we be keeping things consistent with the draft guidance for disposers in general? function dispose() { ... }
return {
dispose,
[SymbolDispose]: dispose,
// or
[SymbolDispose]() { dispose() },
} My vote would be for the latter – it would be an inconsistent pattern for disposables to sometimes be directly callable, and other times not. |
509efeb
to
271fb76
Compare
This comment was marked as outdated.
This comment was marked as outdated.
271fb76
to
f4ca9ae
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58453 +/- ##
==========================================
+ Coverage 90.13% 90.14% +0.01%
==========================================
Files 636 636
Lines 187891 187932 +41
Branches 36878 36883 +5
==========================================
+ Hits 169348 169408 +60
- Misses 11289 11290 +1
+ Partials 7254 7234 -20
🚀 New features to boost your workflow:
|
* Returns: {Object} An object with a dispose method that will remove the listener. | ||
The function will also have a `Symbol.dispose` method so the function can | ||
be used with the `using` keyword. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning an anonymous object in the API makes it hard to discover, like searching API interfaces with [Symbol.dispose]
method. Additionally, the properties of the anynomous objects are not as clear as a named types. I'd prefer a named interface for the event listener disposable type.
This adds new
use(...)
anduseOnce(...)
methodsaddDisposableListener
method toEventEmitter
that returns a disposable object that will unregister the event listeners when disposed, along with two changes that use the new apis to demonstrate how it can be used to simplify some cleanup.