Last active
October 1, 2015 18:12
-
-
Save rdsubhas/bada459c7204886accda to your computer and use it in GitHub Desktop.
es6-blog-callbacks.js
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
var request = require('request'); | |
var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1; | |
function foo(finalCallback) { | |
request.get(url1, function(err1, res1) { | |
if (err1) { return finalCallback(err1); } | |
request.post(url2, function(err2, res2) { | |
if (err2) { return finalCallback(err2); } | |
request.put(url3, function(err3, res3) { | |
if (err3) { return finalCallback(err3); } | |
request.del(url4, function(err4, res4) { | |
// let's stop here | |
if (err4) { return finalCallback(err4); } | |
finalCallback(null, "whew all done"); | |
}) | |
}) | |
}) | |
}) | |
} | |
// use that function somewhere | |
foo(function(err, message) { | |
if (err) { | |
return console.log("error!", err); | |
} | |
console.log("success!", message); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment