Created
August 9, 2018 08:24
-
-
Save odykyi/010d4ce27ffd51c09157de4caba6cacb to your computer and use it in GitHub Desktop.
no try/catch in async/await ( nodejs node node.js js error handling arrow function)
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
module.exports = function of(promise) { | |
return Promise.resolve(promise) | |
.then((ret) => ret) | |
.catch((err) => { | |
if (!err) { | |
let error = new Error("Rejection with empty value"); | |
error.originalValue = err; | |
err = error; | |
} | |
return [undefined, err]; | |
}); | |
} |
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 of = require('./await-of'); | |
(async () => { | |
const fooFunction = async () => { | |
console.log('log', 1111); | |
return 2222; | |
} | |
const res = await of(fooFunction()); | |
console.log('res', res); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment