Last active
April 15, 2022 17:43
-
-
Save Vigowebs/06a605622e311eafcc421e3d42ef2067 to your computer and use it in GitHub Desktop.
Instead of writing nested callbacks, we can write Promise (natively available from Node 4) calls.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ❌ | |
asyncFunc1((err, result1) => { | |
asyncFunc2(result1, (err, result2) => { | |
asyncFunc3(result2, (err, result3) => { | |
console.log(result3) | |
}) | |
}) | |
}) | |
// ✔️ | |
asyncFuncPromise1() | |
.then(asyncFuncPromise2) | |
.then(asyncFuncPromise3) | |
.then((result) => console.log(result)) | |
.catch((err) => console.error(err)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment