Skip to content

Instantly share code, notes, and snippets.

@pifantastic
Created September 7, 2012 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pifantastic/3666728 to your computer and use it in GitHub Desktop.
Save pifantastic/3666728 to your computer and use it in GitHub Desktop.
// Method one, return statement after callback.
// Most clear, but extra line of code.
function asyncBiznis (callback) {
moreAsyncBiznis(function (err, result) {
if (err) {
callback( new Error("Hope is lost.") );
return;
}
// More logic...
});
});
// Method two, return on callback.
// Less clear, but saves a line of code.
function asyncBiznis (callback) {
moreAsyncBiznis(function (err, result) {
if (err) {
return callback( new Error("Hope is lost.") );
}
// More logic...
});
});
// Method three, wrap all other logic in else{}
// Also clear, but results in extra indentation.
function asyncBiznis (callback) {
moreAsyncBiznis(function (err, result) {
if (err) {
callback( new Error("Hope is lost.") );
}
else {
// More logic...
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment