-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_using_async_await.js
50 lines (37 loc) · 1005 Bytes
/
6_using_async_await.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
50
let stocks = {
Fruits:['strawberry', 'grapes', 'banana', 'apple'],
ligquid: ['water', 'ice'],
holder:['cone', 'cup', 'stick'],
toppings:['chocolate', 'peanuts']
};
let is_shop_open = false;
function time(ms){
return new Promise( (resolve, reject)=>{
if(is_shop_open){
setTimeout(()=>{
resolve()
}, ms);
}else{
reject(console.log('Uh no, shop is closed!'))
}
} )
}
async function kitchen() {
try {
await time(0000)
console.log(`which flavour would you like?`)
await time(1000)
console.log(`${stocks.Fruits[0]} is selected`)
await time(1000)
console.log('start the production')
await time(1000)
console.log('water selected.')
await time(2000)
console.log('ice cream served')
} catch (error) {
console.log('customer left.')
} finally{
console.log('shop closed')
}
}
kitchen()