Skip to content

Instantly share code, notes, and snippets.

@gonzofish
Created November 13, 2019 13:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gonzofish/b957610e60ef2cde633258c5be62474c to your computer and use it in GitHub Desktop.
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
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