-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathJavascript Promises.js
62 lines (50 loc) · 1.23 KB
/
Javascript Promises.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
const p1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("p1 resolved")
}, 6000)
})
const p2 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("p2 resolved")
}, 3000)
})
async function abc() {
const a = await p1;
console.log(a);
}
async function hello() {
console.log("start");
abc();
console.log("hello before b");
const b = await p2;
console.log(b);
console.log("lkjsd");
}
hello();
// const products = ["a", "b", "c", "lkdsj", "lksd", "lkjs"]
// const cart = createCart(products)
// cart.then(function (orderId) {
// return payment(orderId) // must return this promise to get response in next then() function
// }).then(function (paymentInfo) {
// console.log(paymentInfo)
// })
// .catch(function(err) {
// console.log("error", err)
// })
// function createCart(products) {
// return new Promise(function(resolve, reject) {
// if(products.length > 5) {
// setTimeout(function() {
// resolve("1234");
// }, 3000);
// }
// else {
// reject("Not sufficient product");
// }
// })
// }
// function payment(orderId) {
// return new Promise((resolve, reject) => {
// resolve("payment succcessfully for " + orderId)
// })
// }