Skip to content

Instantly share code, notes, and snippets.

@nilasissen
Created July 3, 2017 12:20
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 nilasissen/8d254cd666826f6c0260e5cfb7e69127 to your computer and use it in GitHub Desktop.
Save nilasissen/8d254cd666826f6c0260e5cfb7e69127 to your computer and use it in GitHub Desktop.
NodeJs async waterfall example
async.waterfall([
function (nextCb) {
if (!topicData.user_id || typeof topicData.user_id === undefined) {
nextCb(null, { "response_code": 5002, "response_message": "please provide user id.", "response_data": {} });
}
else {
nextCb(null, { "response_code": 2000 });
}
},
function (arg1, nextCb) {
if (arg1.response_code === 5002) {
nextCb(null, arg1);
}
if (arg1.response_code === 2000) {
//call the function(){
nextCb(null, arg1);
}
}
}
], function (err, content) {
if (err) {
callback({
"response_code": 5005,
"response_message": "INTERNAL DB ERROR",
"response_data": {}
})
}
if (!err) {
if (content.response_code === 2000) {
callback({
"response_code": 2000,
"response_message": "",
"response_data": {
}
})
}
if (content.response_code === 5002) {
callback(content);
}
if (content.response_code === 5005) {
callback(content);
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment