Skip to content

Commit 9657b13

Browse files
committed
Updates basic/nextTick-setTimeout.md
Auto commit by GitBook Editor
1 parent c67e215 commit 9657b13

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

basic/nextTick-setTimeout.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,26 @@
1717
1818
You shouldn’t necessarily be concerned about the order of operations in this regard though in my estimation.
1919
```
20-
但是在node.js 8.1
20+
但是在node.js 最新版本(8.2.1),setTimeout都比setImmediate先执行。
21+
```
22+
var res = [];
23+
24+
setImmediate(function() {
25+
res.push(2)
26+
});
27+
setTimeout(function() {
28+
res.push(1)
29+
}, 0);
30+
31+
res.push(3)
32+
process.nextTick(function() {
33+
res.push(4)
34+
});
35+
36+
setImmediate(function() {
37+
console.log(res)//[3,4,1,2]
38+
});
39+
```
2140

2241

2342
### 举例

0 commit comments

Comments
 (0)