-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
‘timersPromises.setInterval()’ doesn’t keep the event loop active #45224
Comments
Don't you need to |
|
@mscdex Thanks for the response. No, I don’t think that Note that the desired behavior I’m describing is what occurs with // index.mjs
import timers from "node:timers/promises";
timers.setTimeout(1000); @theanarkh Thanks for the response. Great idea. I can confirm that I think it’s a bit weird that it appears as if the timer is only being registered if you query for a value. I think that the timer should have been registered as soon as Do you agree? Or do you think I’m misunderstanding something? |
Yeah, because this usage is different from |
@theanarkh So I suppose we have an opportunity to either (in order of preference):
What do y’all think we should do? Also, for what it’s worth, it seems like TypeScript doesn’t know about the fact that you may call // index.mts
import timers from "node:timers/promises";
timers.setInterval(1000)[Symbol.asyncIterator]().next(); |
I think we can explain this in more detail in the documentation :-). |
PR-URL: nodejs#45232 Refs: nodejs#45224 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Version
v18.12.0
Platform
Darwin leafac--mac-mini.lan 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101 arm64
Subsystem
No response
What steps will reproduce the bug?
As far as I understand from having read the documentation,
timersPromises.setInterval()
was supposed to keep the event loop active, in much the same way that other timers includingsetInterval()
do. That’s why one of the possibleoptions
isref
.But that doesn’t seem to be working.
Here’s an example program:
This program exits immediately. I tried changing the
ref
option, including setting it totrue
explicitly, to no effect.Here’s a similar program using
setInterval()
, which does keep the event loop active and does not terminate right away:This may seem like a silly program, but sometimes it’s actually useful to have a dummy timer like that to exert more control over the event loop and when it terminates.
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
No response
What do you see instead?
—
Additional information
No response
The text was updated successfully, but these errors were encountered: