-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (48 loc) · 1.36 KB
/
index.js
File metadata and controls
65 lines (48 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function getB() {
const b = 1;
return new Promise((resolve) => {
resolve(b);
});
}
async function test() {
console.log('Started test...'); // ? - 2
setTimeout(() => {
console.log('Set timeout callback #1'); // ? - 9
}, 2000);
getB().then((b) => console.log('Getting b from then ..., b: ', b)); // ? -5
console.log('Some code ...'); // ? - 3
const b = await getB(); асинх
console.log('from await, b: ', b); // ? - 6
setTimeout(() => {
console.log('Set timeout callback #2') // ? - 8
});
return 200;
}
console.log('Main Thread'); // ? - 1
test().then((code) => {
console.log('Test is ended, code: ', code) // ? - 7 200
});
console.log('Other Sync code in Main Thread'); // ? - 4
setTimeout(() => {
console.log('Outer set timeout #1') // ? аснинх -
}, 0);
// 1.Main thread
// 2.Other Sync code in Main Thread
// 3.Started test...
// 4.Getting b from then ..., b: 1
// 5.Some code ...
// 6.from await, b: 1
// 7.Outer set timeout #1
// 8.Set timeout callback #2
// 9.Set timeout callback #1
// 10.Test is ended, code: 200
Main Thread
Started test...
Some code ...
Other Sync code in Main Thread
Getting b from then ..., b: 1
from await, b: 1
Test is ended, code: 200
Outer set timeout #1
Set timeout callback #2
Set timeout callback #1