Created
April 19, 2018 13:53
-
-
Save ibratoev/3723891d81b98b94f7dec04b979164ff to your computer and use it in GitHub Desktop.
Async-await vs then with not well behaving functions
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
const shouldReturnPromise = () => { throw "test"; } | |
const withAsyncAwait = async () => { | |
try { | |
await shouldReturnPromise() | |
} catch (e) { | |
console.log('Handled: ' + e) | |
} | |
} | |
const withPromise = async () => { | |
shouldReturnPromise().then(null, () => console.log('Not Handled!')); | |
} | |
console.log(withAsyncAwait()); | |
console.log(withPromise()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Totally aligned 👍 The current code was moved from the Hype project. I would use
async/await
as I find it safer and simpler.