Created
February 26, 2018 22:47
-
-
Save 4lg4/924046516802281a6dc97a7e291e67d5 to your computer and use it in GitHub Desktop.
Node.js: async process, a way to avoid huge try {} catch blocks in JS using GO approach
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 asyncProcess = async (promise) => { | |
try { | |
return [null, await promise]; | |
} catch (err){ | |
return [err]; | |
} | |
}; | |
const [err,result] = await asyncProcess(__MyPromise__); | |
if(err) { | |
return err; | |
} | |
if(!result) { | |
return 'Nothing found' | |
} | |
return result; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment