Created
March 29, 2017 13:02
-
-
Save Eli-Goldberg/de671840cd48fe76b1fff559363ad087 to your computer and use it in GitHub Desktop.
Co with Promises
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
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