-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawait.1.js
49 lines (44 loc) · 1.1 KB
/
await.1.js
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
function checkLocation(location) {
return new Promise((resolve, reject) => {
if(Object.is(location, 'HaNoi'))
return resolve('HaNo Nice');
return reject('Another Places');
})
}
// checkLocation('HaNoi')
// .then(message => console.log(message))
// .catch(err => console.err(err));
function who() {
return new Promise(resolve => {
setTimeout(() => {
console.log(`WHO`)
resolve('WHO');
}, 5000);
})
}
function what() {
return new Promise(resolve => {
setTimeout(() => {
console.log(`WHAT`)
resolve('WHAT');
}, 2000);
})
}
function where() {
return new Promise(resolve => {
setTimeout(() => {
console.log(`WHERE`)
resolve('WHERE');
}, 3000);
})
}
var start = new Date().getTime();
async function runWithAsync(){
let mssWho = await who();
let mssWhere = await where();
let mssWhat = await what();
console.log({ mssWho, mssWhere, mssWhat })
var end = new Date().getTime();
console.log(end - start);
};
runWithAsync();