forked from Backslash-Computing-Society/Hacktober
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromises.js
More file actions
38 lines (32 loc) · 674 Bytes
/
promises.js
File metadata and controls
38 lines (32 loc) · 674 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
let p1 = async()=>{
return new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve("value 1")
},2000)
})};
let p2 = async()=>{
return new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve("value 2")
},1000)
})};
let p3 = async()=>{
return new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve("value 3")
},3000)
})};
let a = async()=>{
console.time("run");
// let a1= await p1();
// let a2 = await p2();
// let a3 = await p3();
// console.log(a1,a2,a3);
let a1=p1();
let a2=p2();
let a3=p3();
let a1a2a3 =await Promise.all([a1,a2,a3])
console.log(a1a2a3);
console.timeEnd("run");
};
a();