Skip to content
This repository was archived by the owner on Jan 24, 2023. It is now read-only.

Commit 589997f

Browse files
committed
Add promise sample 🙌
1 parent a70cb7d commit 589997f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

promises/calculation.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// We will transform this to promise
2+
// setTimeout(function() {
3+
// console.log(1 + 1);
4+
// }, 1000)
5+
6+
var calculationPromise = new Promise(function(resolve, reject) {
7+
setTimeout(function() {
8+
console.log(1 + 1);
9+
}, 1000)
10+
});
11+
12+
function addTwo(value) {
13+
return value + 2;
14+
}
15+
16+
function printFinalValue(nextValue) {
17+
console.log("The final value is ", nextValue);
18+
}
19+
20+
calculationPromise
21+
.then(addTwo)
22+
.then(printFinalValue);
23+
24+
// Easy to read

0 commit comments

Comments
 (0)