Last active
June 26, 2018 05:39
-
-
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 contains hidden or 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
// this file exists just to name the gist, and because gist ordering is asciibetical, it's name starts with a capital letter. |
This file contains hidden or 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
/** | |
* 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]; | |
}); | |
}; |
This file contains hidden or 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
{ | |
"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