Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upevents: add EventEmitter.on to async iterate over events #27994
Conversation
| }, | ||
|
|
||
| throw(err) { | ||
| // TODO should we validate that err exists? |
This comment has been minimized.
This comment has been minimized.
benjamingr
May 31, 2019
Member
No, I think we shouldn't since it is allowed to throw undefined. I really hope users don't actually do it.
This comment has been minimized.
This comment has been minimized.
|
CC @davidmarkclements since you maintain the |
6e69e8d
to
b6542f0
This comment has been minimized.
This comment has been minimized.
|
I like this!! One test case seems to have a bug. I'm not sure what caused it Gist code Specific steps for recurrence:
It is clear that the async function exits directly after the |
This comment has been minimized.
This comment has been minimized.
thanks @benjamingr - I've had the |
|
Thank you! |
| @@ -694,6 +694,37 @@ async function run() { | |||
| run(); | |||
| ``` | |||
|
|
|||
| ## events.on(emitter, event) | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@zero1five thanks for the test case, definitely relevant I'll look into it when I'm in front of a computer |
This comment has been minimized.
This comment has been minimized.
|
@zero1five hey, I ran your code example but I wasn't able to figure out what the confusing part was. Do you mean how that pending promises do not keep the event loop live if there is no scheduled I/O? |
This comment has been minimized.
This comment has been minimized.
|
Some events in node core emit a single value. Would it be possible to add an option to this api to return the first value emitted instead of an array of all values emitted. |
This comment has been minimized.
This comment has been minimized.
|
@Raynos hey, long time no see. Happy to see you around here :] Node already shipped (recently) an EventEmitter.once static method that does just that. https://nodejs.org/api/events.html#events_events_once_emitter_name |
This comment has been minimized.
This comment has been minimized.
I was at the openjs summit in berlin, next time I see you i'll say hello properly.
I meant an option to return the first value emitted, aka The current implementation would require some destructuring in the common case
|
This comment has been minimized.
This comment has been minimized.
|
@Raynos lol, I had no idea we were in the same room for two days :) definitely say hi next time! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
CI passed. I think this is ready to land? |
This comment has been minimized.
This comment has been minimized.
|
Landed in 38a593b |
Notable changes:
* assert:
* Implement `assert.match()` and `assert.doesNotMatch()` (Ruben
Bridgewater) #30929
* events:
* Add `EventEmitter.on` to async iterate over events (Matteo Collina)
#27994
* Allow monitoring error events (Gerhard Stoebich)
#30932
* fs:
* Allow overriding `fs` for streams (Robert Nagy)
#29083
* perf_hooks:
* Move `perf_hooks` out of experimental (legendecas)
#31101
* repl:
* Implement ZSH-like reverse-i-search (Ruben Bridgewater)
#31006
* tls:
* Add PSK (pre-shared key) support (Denys Otrishko)
#23188
Notable changes:
* assert:
* Implement `assert.match()` and `assert.doesNotMatch()` (Ruben
Bridgewater) #30929
* events:
* Add `EventEmitter.on` to async iterate over events (Matteo Collina)
#27994
* Allow monitoring error events (Gerhard Stoebich)
#30932
* fs:
* Allow overriding `fs` for streams (Robert Nagy)
#29083
* perf_hooks:
* Move `perf_hooks` out of experimental (legendecas)
#31101
* repl:
* Implement ZSH-like reverse-i-search (Ruben Bridgewater)
#31006
* tls:
* Add PSK (pre-shared key) support (Denys Otrishko)
#23188
PR-URL: #31238
Notable changes:
* assert:
* Implement `assert.match()` and `assert.doesNotMatch()` (Ruben
Bridgewater) #30929
* events:
* Add `EventEmitter.on` to async iterate over events (Matteo Collina)
#27994
* Allow monitoring error events (Gerhard Stoebich)
#30932
* fs:
* Allow overriding `fs` for streams (Robert Nagy)
#29083
* perf_hooks:
* Move `perf_hooks` out of experimental (legendecas)
#31101
* repl:
* Implement ZSH-like reverse-i-search (Ruben Bridgewater)
#31006
* tls:
* Add PSK (pre-shared key) support (Denys Otrishko)
#23188
PR-URL: #31238
Notable changes:
* assert:
* Implement `assert.match()` and `assert.doesNotMatch()` (Ruben
Bridgewater) #30929
* events:
* Add `EventEmitter.on` to async iterate over events (Matteo Collina)
#27994
* Allow monitoring error events (Gerhard Stoebich)
#30932
* fs:
* Allow overriding `fs` for streams (Robert Nagy)
#29083
* perf_hooks:
* Move `perf_hooks` out of experimental (legendecas)
#31101
* repl:
* Implement ZSH-like reverse-i-search (Ruben Bridgewater)
#31006
* tls:
* Add PSK (pre-shared key) support (Denys Otrishko)
#23188
PR-URL: #31238
| } | ||
|
|
||
| // If the iterator is finished, resolve to done | ||
| if (finished) { |
This comment has been minimized.
This comment has been minimized.
jayflo
Jan 30, 2020
•
Stupid question: how does finished get set to true in the non-error case? From what I see here, after the final event is resolved, won't the for await of loop will be waiting on a promise from unconsumedPromises? It seems like some sort of "on finished" callback would be needed.
mcollina commentedMay 31, 2019
Fixes: #27847.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes