| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Review requested:
|
Sorry, something went wrong.
|
Relevant to advancing on this: #58526 |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
What change in behavior are you concerned about? This should not change any existing behavior of the EventEmitter |
Sorry, something went wrong.
|
I've updated the implementation to rename the use method to a single addDisposableListener method with a once option. It returns a dispose function that has the Symbol.dispose property attached to call itself. PTAL |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM with removal of obsolete no-undefs 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.
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
Not without adding too much complexity. As it is now, addListener(...) returns the EventEmitter itself. Adding an option would mean making the return value polymorphic which is far worse than adding a new separate API. See the discussion around #58526 |
Sorry, something went wrong.
|
Regarding the single-use disposable that's just a disposer, with no associated object data: is function dispose() { ... }
dispose[SymbolDispose] = dispose
return disposeOK, 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. |
Sorry, something went wrong.
Sorry, something went wrong.
Codecov ReportAttention: Patch coverage is 98.66667% with 1 line in your changes missing coverage. Please review.
@@ 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
... and 34 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Sorry, something went wrong.
| * 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.
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.
Sorry, something went wrong.
|
@nodejs/tsc ... I'd still like some opinions on whether y'all think this is a good idea or not. |
Sorry, something went wrong.
|
Closing given lack of responses to pings. Would appears there's not much interest in this |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This adds new use(...) and useOnce(...) methods addDisposableListener method to EventEmitter 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.