-
Notifications
You must be signed in to change notification settings - Fork 0
/
day27.js
117 lines (84 loc) · 1.78 KB
/
day27.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// async-await recape
let func =(a,b)=>{
console.log(a+b);
}
func(8,8)
let stocks = {
Fruits : ["strawberry", "grapes", "banana", "apple"],
liquid : ["water", "ice"],
holder : ["cone", "cup", "stick"],
toppings : ["chocolate", "peanuts"],
};
let is_shop_open = false;
// promises outline
// let order=(()=>{
// return new Promise((resolve,reject)=>{
// if(true){
// resolve()
// }
// else{
// reject()
// }
// })
// })
// order()
// .then()
// .then()
// .then()
// .catch()
// .finally()
// sync and await starts from here !
// let toppings_choice=()=>{
// return new Promise((resolve,reject)=>{
// setTimeout(()=>{
// resolve(console.log("which topping you like?"))
// },3000)
// })
// }
// async function kitchen(){
// console.log("A");
// console.log("B");
// console.log("C");
// await toppings_choice()
// console.log("D");
// console.log("E");
// }
// kitchen()
// console.log("cleaning tables");
// console.log("cleaning dishes");
// console.log("other works");
function time(ms){
return new Promise((resolve,reject)=>{
if(is_shop_open){
setTimeout((ms)=>{
resolve(200)
},ms)
}
else{
reject(console.log("shop is under construction"))
}
})
}
async function kitchen(){
try {
await time(2000)
console.log(`${stocks.Fruits[2]}`);
await time(1000)
console.log(`processing step2`);
await time(2000)
console.log(`processing step3`);
await time(3000)
console.log(`processing step4`);
await time(1000)
console.log(`processing step5`);
await time(3000)
console.log(`processing step6`);
}
catch(error){
console.log("customer left");
}
finally {
console.log("shop is closed finally");
}
}
kitchen()