etn*_*brd 9 javascript node.js
我在节点文档中读到了这个:
setImmediate(callback,[arg],[...])
在I/O事件回调之后以及之前
setTimeout和之后安排"立即"执行回调setInterval
但是,我看到相反的情况.
setTimeout之前执行setImmediate.是否有人对此行为进行了解释,或者有关于节点事件循环的任何文档?
谢谢 :)
代码:
var index = 0;
function test(name) {
console.log((index++) + " " + name);
}
setImmediate(function() {
test("setImmediate");
})
setTimeout(function() {
test("setTimeout");
}, 0);
process.nextTick(function() {
test("nextTick");
})
test("directCall");
Run Code Online (Sandbox Code Playgroud)
输出:
0 directCall
1 nextTick
2 setTimeout
3 setImmediate
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1125 次 |
| 最近记录: |