-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventLoop.js
More file actions
41 lines (33 loc) · 743 Bytes
/
eventLoop.js
File metadata and controls
41 lines (33 loc) · 743 Bytes
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
// function a(){
// console.log("a");
// }
// a()
// console.log("end");
// console.log("start");
// setTimeout(()=>{
// console.log('hello!');
// }, 5000);
// console.log("end");
// To use a async and await, function must return a promise.
function fn() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('hello !');
console.log('hello from console !');
reject('An error occurred !');
// resolve('hello');
}, 2000);
}
);
}
const b = (p1, p2)=>{
return p1 + p2;
}
async function a(){
console.log("start");
const result = await fn();
console.log(result);
console.log(b(1,2));;
console.log('end');
}
a();