Comments (3)
It's not that simple, if you run this:
setTimeout(() => {
console.log("timeout");
});
setImmediate(() => {
console.log("immediate");
});
setTimeout(function() {
setTimeout(function() {
console.log('setTimeout')
}, 0);
setImmediate(function() {
console.log('setImmediate')
});
}, 10);
You'll consistently get
timeout
immediate
setImmediate
setTimeout
Quick research shows that there is no hard requirement on the ordering, for example this article says:
A setTimeout() callback with a 0ms delay is very similar to setImmediate(). The execution order will depend on various factors, but they will be both run in the next iteration of the event loop.
In any case, the node's implementation of event loop is quite complex, and it would be non-trivial to implement something that mimics it precisely. Having said that, I'm always open to consider PRs.
from goja_nodejs.
It's not that simple, if you run this:
setTimeout(() => { console.log("timeout"); }); setImmediate(() => { console.log("immediate"); }); setTimeout(function() { setTimeout(function() { console.log('setTimeout') }, 0); setImmediate(function() { console.log('setImmediate') }); }, 10);You'll consistently get
timeout immediate setImmediate setTimeout
Quick research shows that there is no hard requirement on the ordering, for example this article says:
A setTimeout() callback with a 0ms delay is very similar to setImmediate(). The execution order will depend on various factors, but they will be both run in the next iteration of the event loop.
In any case, the node's implementation of event loop is quite complex, and it would be non-trivial to implement something that mimics it precisely. Having said that, I'm always open to consider PRs.
This example it is settimeout block,So it's expected output,but if i have many long time script is run,i can not use setImmediate or other api Insert Before Queue
from goja_nodejs.
As I said, PRs are welcome.
from goja_nodejs.
Related Issues (20)
- Support for `process.env`? HOT 4
- `require('./util')` will return the "native module" that register by `goja_nodejs/util/module.go`, expect is my `util.js` file. HOT 1
- Better example code HOT 2
- NodeJS URL Support
- Prioritise native modules HOT 2
- Performance issue due to native modules being lower priority HOT 1
- setImmediate support HOT 1
- No way to interrupt a script running EventLoop HOT 3
- could you help me understand the example on README HOT 1
- Docs Request
- [Feature]: Support Path module
- how to return valuein eventloop? HOT 1
- join contribution
- Is there any plan to implement http
- EventLoop : Wait for all jobs to finish HOT 7
- [Feature Request] Add a option for disable the `require` method when using EventLoop HOT 1
- EventLoop: runtime management
- evenloop.Run hang with setInterval HOT 3
- Event loop gets stuck unexpectedly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goja_nodejs.