This repository has been archived by the owner on Mar 12, 2021. It is now read-only.
forked from b0rza/summercamp2019-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
74 lines (61 loc) · 1.6 KB
/
app.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
var order1 = 'pizza';
var order2 = 'pineapplePizza';
var makeDough = function() {
return 'dough';
}
var putToppings = function(order, base) {
var toppings = {
pizza: 'tomato, mozzarella, basil',
pineapplePizza: 'pineapple, tomato, mozzarella, basil'
}
return toppings[order] + ' on ' + base;
}
var bake = function(preppedMeal) {
return 'baked: ' + preppedMeal;
}
var cook = function(order) {
var areInstallationsOk = true;
return new Promise(function(resolve, reject) {
if(areInstallationsOk) {
var cookTimes = {
pizza: 3000,
pineapplePizza: 6000
}
var COOK_TIME = cookTimes[order];
var thingThatsTakingTime = function() {
var cookedMeal = bake(putToppings(order, makeDough()));
resolve(cookedMeal);
}
window.setTimeout(thingThatsTakingTime, COOK_TIME);
}
else {
reject('The kitchen blew up!!!');
}
});
}
var serve = function(cookedMeal) {
// var result = 'plate of ' + cookedMeal;
// thingToDoAfterServing(result);
return new Promise(function(thingToDoAfterServing){
var result = 'plate of ' + cookedMeal;
thingToDoAfterServing(result);
});
}
var eat = function(servedMeal) {
var result = 'eat a ' + servedMeal;
console.log(result);
}
var apologize = function(whatHappened) {
console.log("I'm terribly sorry, but " + whatHappened);
}
var haveDinner = function(order1, order2) {
// cook(order)
// .then(serve)
// .then(eat)
// .catch(apologize);
Promise.all([ cook(order1), cook(order2) ])
.then(serve)
.then(eat)
.catch(apologize);
}
haveDinner(order1, order2);