Skip to content

Instantly share code, notes, and snippets.

@gnitnuj
Last active June 26, 2018 05:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gnitnuj/a7401cf383d378ffc56c93152986dded to your computer and use it in GitHub Desktop.
module to handle async/await error handling in a golang kinda way
// this file exists just to name the gist, and because gist ordering is asciibetical, it's name starts with a capital letter.
/**
* goifyPromise
* given a promise, return an array that has the data, and also possibly the error
* @param {Promise}
* @returns {Array}
*/
module.exports = promise => {
return promise
.then(data => {
return [null, data];
})
.catch(err => {
return [err];
});
};
{
"name": "goify-promise",
"version": "0.1.0"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment