Created
March 27, 2020 19:27
-
-
Save abegehr/78ff807ecb9c3cc9359a0d9b9fa1ad39 to your computer and use it in GitHub Desktop.
Promise.then().catch() vs. async, await, try, catch
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
async function call1() { | |
try { | |
return await promise1; | |
} | |
catch (err) { | |
console.warn("promise1 – Error: ", err); | |
} | |
} | |
async function call2() { | |
try { | |
const res = await promise1; | |
return res.body; | |
} | |
catch (err) { | |
console.warn("promise1 – Error: ", err); | |
} | |
} | |
Promise.all([call1(), call2()]) | |
.then([data, body] => {…}) |
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
Promise.all([ | |
promise1 | |
.catch(err => console.warn("promise1 – Error: ", err)), | |
promise2 | |
.then(res => res.body) | |
.catch(err => console.warn("promise2 – Error: ", err)) | |
]).then([data, body] => {…}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment