Skip to content

Commit bd798fa

Browse files
committed
feat: add event loop in browser
1 parent 5f85006 commit bd798fa

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

js/event_loop_browser.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* @Author: Chacha
3+
* @Date: 2022-04-04 21:18:16
4+
* @Last Modified by: Chacha
5+
* @Last Modified time: 2022-04-04 22:39:58
6+
*/
7+
8+
/**
9+
*
10+
* Event Loop 在浏览器中的测试用例
11+
*
12+
*/
13+
console.log("1");
14+
15+
setTimeout(function () {
16+
console.log("2");
17+
new Promise(function (resolve) {
18+
console.log("3");
19+
resolve();
20+
}).then(function () {
21+
console.log("4");
22+
});
23+
setTimeout(function () {
24+
console.log("5");
25+
new Promise(function (resolve) {
26+
console.log("6");
27+
resolve();
28+
}).then(function () {
29+
console.log("7");
30+
});
31+
});
32+
console.log("14");
33+
});
34+
35+
new Promise(function (resolve) {
36+
console.log("8");
37+
resolve();
38+
}).then(function () {
39+
console.log("9");
40+
});
41+
42+
setTimeout(function () {
43+
console.log("10");
44+
new Promise(function (resolve) {
45+
console.log("11");
46+
resolve();
47+
}).then(function () {
48+
console.log("12");
49+
});
50+
});
51+
52+
console.log("13");
53+
54+
// 1->8->13->9->2->3->14->4->10->11->12->5->6->7

js/event_loop_in_browser.png

355 KB
Loading

0 commit comments

Comments
 (0)