-
Notifications
You must be signed in to change notification settings - Fork 29.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
Emit event when code in vm is fully executed #31240
Comments
There is really no way to know short of solving the Halting Problem. Example: a promise handler can always enqueue a new promise, which in turn can enqueue a new promise, etc. It might be possible to implement some kind of "kill switch" that forcibly terminates the script and all outstanding microtasks/handles/requests/etc., but that's about it. But then you might as well use workers.
That's probably impossible because you can't nest event loops for technical reasons. Example: on some platforms where node uses kqueue for its event loop (macos, the BSDs), adding a kqueue fd to another kqueue fd doesn't work because the nested fd doesn't generate events. It also doesn't really solve the issue of microtasks/promises. |
I was afraid you'd say that :/
Yes, this will work. Sharing code between worker threads is harder but I now can tell that changing how VM works is harder. Thank you for the thorough explanation @bnoordhuis! |
I'll go ahead and close this out then. Thanks anyway for opening the issue! |
Is your feature request related to a problem? Please describe.
There is no way to know if the script running in vm is fully executed or not. Of course, all synchronous tasks are immediately executed when
runInContext
is called. But since all contexts share the event loop, we cannot tell if there are any more callbacks (of the vm code) in the event loop. (e.g. asetTimeout
callback)Describe the solution you'd like
vm.Script
should use a separate event loop and emit an event when there are no more callbacks left.Describe alternatives you've considered
As bnoordhuis stated, we can add bookkeeping to every call into the VM.
The text was updated successfully, but these errors were encountered: