Created
July 3, 2017 12:20
-
-
Save nilasissen/8d254cd666826f6c0260e5cfb7e69127 to your computer and use it in GitHub Desktop.
NodeJs async waterfall example
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
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