-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
events: timing issue awaiting multiple events emitted in same nextTick #32431
Comments
I agree that this looks like a problem to investigate. I don’t think we have a solution, or a solution is possible without a perf cost. |
I don’t think there’s anything we can do about this besides maybe documenting this – I would say it’s expected behaviour that can still be surprising sometimes. |
Yeah, there's really nothing that can be done without a major refactor or a major perf hit. I think documenting is the only way to go |
Hi, I was wondering where in the docs should this go. If someone can point me to the appropriate section, I'd be happy to log this behavior. |
@hassaanp ... my apologies for not seeing your comment earlier. This should likely best be added as a subsection to the documentation for the Note that the same issue arises when using the |
Fixes: #32431 PR-URL: #34220 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Fixes: #32431 PR-URL: #34220 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Fixes: #32431 PR-URL: #34220 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Fixes: #32431 PR-URL: #34220 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Just leaving this here as an issue worth investigating. Not sure there's anything we can do about it other than documenting it...
Multiple events emitted on the same
process.nextTick()
may be missed when usingawait once()
. For example, when running the following, both the'bar'
and'foo'
events are emitted but theasync function foo()
never completes becauseawait once(myEE, 'foo')
occurs after thefoo
event is actually emitted.The only way to catch both events is to use
Promise.all()
orPromise.allSettled()
, or to not useawait
withonce(myEE, 'bar')
Why does this happen? It is because the process.nextTick is processed before the microtask queue. Both events are emitted synchronously before the microtask queue is processed. The
await once(myEE, 'bar')
does not continue until the microtask queue is executed, after the'foo'
event is emitted, soawait once(myEE, 'foo')
ends up waiting forever, having missed the actual event.The text was updated successfully, but these errors were encountered: