Feature request: allow awaiting event, reject on "error"
#21339
Labels
duplicate
Issues and PRs that are duplicates of other issues or PRs.
events
Issues and PRs related to the events subsystem / EventEmitter.
feature request
Issues that request new features to be added to Node.js.
Edit: Added
errorEvent
option to configure error events99% of my event adaptation of promises end up looking something close to this:
This is most frequently with streams, but it also occasionally shows up with other things, including with non-core libraries. What I'd prefer to write is something closer to this:
My proposed API is this:
ee.awaitEvent("name", {includeAll = false, errorEvent = "event"} = {})
: Return a promise fulfilled with an array of arguments once"name"
is emitted, rejected if it's beat by an"error"
event. An extra options object is permitted, and it accepts two options:includeAll
, which resolves with an array of arguments intead, anderrorEvent
, which allows configuring what event is considered the "error" event.The naïve implementation is pretty simple, and looks very similar to above.
The text was updated successfully, but these errors were encountered: