-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromise_chaining.js
More file actions
55 lines (48 loc) · 1.22 KB
/
Copy pathPromise_chaining.js
File metadata and controls
55 lines (48 loc) · 1.22 KB
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
function placeOrder() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log("Order Placed");
resolve();
}, 5000)
})
}
function makePayment() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log("Payment Received");
resolve();
}, 2000)
})
}
function confirmOrder() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log("Order Confirmed");
resolve();
}, 2000)
})
}
function sendEmail() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log("Email has been sent Successfully");
resolve();
}, 1000)
})
}
// placeOrder()
// .then(async () => await makePayment())
// .then(async () => await confirmOrder())
// .then(async () => await sendEmail())
// .then(() => console.log("PROCESS ENDED."))
// .catch((err) => console.log(err))
async function processOrder() {
console.log("Process Started");
await placeOrder();
await makePayment();
await confirmOrder();
await sendEmail();
console.log("PROCESS ENDED.")
}
processOrder();
console.log("OTHER TASK");