Skip to content

Instantly share code, notes, and snippets.

@rdsubhas
Last active October 1, 2015 18:11
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 rdsubhas/044815c48f9fddb7ac96 to your computer and use it in GitHub Desktop.
Save rdsubhas/044815c48f9fddb7ac96 to your computer and use it in GitHub Desktop.
es6-blog-promises.js
var Promise = require('bluebird');
var request = Promise.promisifyAll(require('request'));
var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1;
function foo() {
return request.getAsync(url1)
.then(function(res1) {
return request.postAsync(url2);
}).then(function(res2) {
return request.putAsync(url3);
}).then(function(res3) {
return request.delAsync(url4);
}).then(function(res4) {
return "whew all done";
});
}
// use that function somewhere
foo().then(function(message) {
console.log("success!", message);
}).catch(function(err) {
console.log("error!", err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment