Skip to content

Instantly share code, notes, and snippets.

@rdsubhas
Last active May 2, 2017 19:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rdsubhas/558b222ee1b1cc46b5e9 to your computer and use it in GitHub Desktop.
Save rdsubhas/558b222ee1b1cc46b5e9 to your computer and use it in GitHub Desktop.
es6-blog-generators.js
var Promise = require('bluebird');
var request = Promise.promisifyAll(require('request'));
var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1;
function* foo() {
var res1 = yield request.getAsync(url1);
var res2 = yield request.getAsync(url2);
var res3 = yield request.getAsync(url3);
var res4 = yield request.getAsync(url4);
return "whew all done";
}
foo = Promise.coroutine(foo);
// 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