Skip to content
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

setImmediate support #47

Closed
gbl08ma opened this issue Feb 19, 2023 · 1 comment
Closed

setImmediate support #47

gbl08ma opened this issue Feb 19, 2023 · 1 comment

Comments

@gbl08ma
Copy link
Contributor

gbl08ma commented Feb 19, 2023

I think one simple and useful nodejs compatibility "win" would be to implement setImmediate/clearImmediate. Looking at the code, the "aux jobs" mechanism already seems to implement exactly the semantics of setImmediate (source):

When multiple calls to setImmediate() are made, the callback functions are queued for execution in the order in which they are created. The entire callback queue is processed every event loop iteration. If an immediate timer is queued from inside an executing callback, that timer will not be triggered until the next event loop iteration.

and it is easy enough to make setImmediate available to the goja environment without changing the eventloop implementation, using RunOnLoop. And clearImmediate can probably also be implemented by checking some condition relative to each Immediate on the RunOnLoop callback before calling the JS callback, but this feels like it could be slightly more optimized if we could remove entries from loop.auxJobs instead. Do you think this warrants being part of the eventloop core, or is it best to just implement it outside the package?

@dop251
Copy link
Owner

dop251 commented Feb 20, 2023

Sounds good to me. Removing from loop.auxJobs is probably not worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants