Created
February 23, 2016 10:44
-
-
Save neurotech/baf8d190aa7d25b93226 to your computer and use it in GitHub Desktop.
ES6 Generators
This file contains hidden or 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
'use strict'; | |
const got = require('got'); | |
const gotIt = url => { | |
got(url) | |
.then(data => { | |
generate.next(data.body); | |
}) | |
.catch(error => { | |
console.error(error); | |
}); | |
}; | |
function * query () { | |
var a = yield gotIt('http://jsonplaceholder.typicode.com/posts/1'); | |
var b = yield gotIt('http://jsonplaceholder.typicode.com/users/1'); | |
console.log(a); | |
console.log(b); | |
} | |
var generate = query(); | |
generate.next(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment