Skip to content

Instantly share code, notes, and snippets.

@4lg4
Created February 26, 2018 22:47
Show Gist options
  • Save 4lg4/924046516802281a6dc97a7e291e67d5 to your computer and use it in GitHub Desktop.
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
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