Skip to content

Instantly share code, notes, and snippets.

@Eli-Goldberg
Created March 29, 2017 13:02
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 Eli-Goldberg/de671840cd48fe76b1fff559363ad087 to your computer and use it in GitHub Desktop.
Save Eli-Goldberg/de671840cd48fe76b1fff559363ad087 to your computer and use it in GitHub Desktop.
Co with Promises
const co = require('co');
const request = require('request');
const bluebird = require('bluebird');
const requestPromisified = bluebird.promisifyAll(request); // This just adds Async to everything
function* goToThere(url) {
console.log('Just started');
const someData = yield const requestPromisified.getAsync(url)
console.log('Yes, I DO have data ' + someData);
return someData;
}
co(function* () {
console.log('Brace yourself');
cosnst someData = yield goToThere('http://just.some.place.com');
console.log('All abord the coroutines with ' + 'someData');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment