Created
November 13, 2019 13:52
-
-
Save gonzofish/b957610e60ef2cde633258c5be62474c to your computer and use it in GitHub Desktop.
Just a simple wrapper for async/await that handles errors without a lot 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
const identity = (value) => value; | |
const esync = (promise, formatResult = identity) => ( | |
promise.then(async (result) => [undefined, await formatResult(result)]) | |
.catch((error) => [error]) | |
); | |
export default esync; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment