-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasync-await.js
90 lines (64 loc) · 2.19 KB
/
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
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
pizzaProbability = 97; // declared in main.js
/* Similar promise that we previously used */
function makeModernPizza (customer) {
return new Promise( function(resolve, reject) {
setTimeout( function() {
const pizzaHasBeenMade = pizzaMakingEvent();
console.log(`${customer}'s pizza has been made:`, pizzaHasBeenMade);
if (pizzaHasBeenMade) {
resolve(customer + ' Success! ');
}
else {
reject('there was a problem with ' + customer + '\'s pizza.');
}
}, lag(maxPizzaLag, maxPizzaLag));
})
}
// async function serveTableFromSingleSmallOven() {
// orderPlaced('sequential-async-await');
// // Sequential
// // there's only one oven, so each pizza needs to be made and cooked
// // before the next pizza
// // and we only want to serve once they're all cooked
// try {
// let alicePizzaMade = await makeModernPizza('Alice');
// let bobbyPizzaMade = await makeModernPizza('Bobby');
// let charliePizzaMade = await makeModernPizza('Charlie');
// orderServed('sequential-async-await');
// // console.log(alicePizzaMade)
// // console.log(bobbyPizzaMade)
// // console.log(charliePizzaMade)
// } catch (error) {
// oops(error)
// }
// }
// serveTableFromSingleSmallOven()
// /* NOTE: Not Async-Await, just a promise version of the Pizza Making example */
// function serveTableFromMultipleLargeOvens() {
// orderPlaced('consecutive-async-await')
// // Mostly consecutive
// // there are lots of ovens, so each pizza can be made and cooked
// // at the same time as the other's pizzas
// // but we still only want to serve once they're all cooked
// let alicePizzaMade = makeModernPizza('Alice');
// let bobbyPizzaMade = makeModernPizza('Bobby');
// let charliePizzaMade = makeModernPizza('Charlie');
// // console.log(alicePizzaMade)
// // console.log(bobbyPizzaMade)
// // console.log(charliePizzaMade)
// Promise.all([
// alicePizzaMade,
// bobbyPizzaMade,
// charliePizzaMade,
// ])
// .then(() => {
// orderServed('consecutive-async-await')
// // console.log(alicePizzaMade)
// // console.log(bobbyPizzaMade)
// // console.log(charliePizzaMade)
// })
// .catch((error) => {
// oops(error)
// })
// }
// serveTableFromMultipleLargeOvens()