Skip to content

Commit b7d6629

Browse files
authored
Create Promise 2.js
1 parent 9e4c752 commit b7d6629

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

Promise 2.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const p1 = new Promise((resolve, reject) => {
2+
setTimeout(() => {
3+
resolve("p1 resolved")
4+
}, 6000)
5+
})
6+
7+
const p2 = new Promise((resolve, reject) => {
8+
setTimeout(() => {
9+
resolve("p2 resolved")
10+
}, 3000)
11+
})
12+
13+
async function abc() {
14+
15+
const a = await p1;
16+
console.log(a);
17+
18+
}
19+
20+
async function hello() {
21+
22+
console.log("start");
23+
abc();
24+
console.log("hello before b");
25+
const b = await p2;
26+
console.log(b);
27+
console.log("lkjsd");
28+
}
29+
30+
hello();
31+
32+
33+
34+
// const products = ["a", "b", "c", "lkdsj", "lksd", "lkjs"]
35+
36+
// const cart = createCart(products)
37+
// cart.then(function (orderId) {
38+
// return payment(orderId) // must return this promise to get response in next then() function
39+
// }).then(function (paymentInfo) {
40+
// console.log(paymentInfo)
41+
// })
42+
// .catch(function(err) {
43+
// console.log("error", err)
44+
// })
45+
46+
// function createCart(products) {
47+
// return new Promise(function(resolve, reject) {
48+
// if(products.length > 5) {
49+
// setTimeout(function() {
50+
// resolve("1234");
51+
// }, 3000);
52+
// }
53+
// else {
54+
// reject("Not sufficient product");
55+
// }
56+
// })
57+
// }
58+
// function payment(orderId) {
59+
// return new Promise((resolve, reject) => {
60+
// resolve("payment succcessfully for " + orderId)
61+
// })
62+
// }

0 commit comments

Comments
 (0)