Skip to content

Commit ccb7fe4

Browse files
committed
Promises
1 parent 5902df1 commit ccb7fe4

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

notes/promises.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Document</title>
7+
</head>
8+
9+
<body>
10+
<script>
11+
var x = 0
12+
</script>
13+
<script>
14+
// You order 🍅 tomato soup
15+
// Meanwhile you continue your convo with a friend
16+
// RESOLVED - 🍲 your server brings you soup
17+
// REJECTED - ❌ No soup today.
18+
19+
// setTimeout(() => {
20+
// console.log("soup")
21+
// }, 2000)
22+
23+
const orderSooup = () => console.log("soup")
24+
25+
console.log("You start the convo with your friend 👳‍♂️!")
26+
setTimeout(orderSooup, 2000)
27+
console.log("Still speaking")
28+
29+
const promise1 = new Promise((resolve, reject) => {
30+
setTimeout(() => {
31+
isReady = [true, false][Math.floor(Math.random() * 2)]
32+
isReady ? resolve("✅soup is ready 🍲") : reject("❌No soup today 🍲")
33+
}, 3000)
34+
})
35+
36+
// promise1.then((message) => console.log(message)).catch((error) => console.error(error))
37+
console.log(promise1.then((success) => console.log({ success })).catch((error) => console.log({ error })))
38+
</script>
39+
</body>
40+
</html>

0 commit comments

Comments
 (0)