Skip to content

Instantly share code, notes, and snippets.

@neurotech
Created February 23, 2016 10:44
Show Gist options
  • Save neurotech/baf8d190aa7d25b93226 to your computer and use it in GitHub Desktop.
Save neurotech/baf8d190aa7d25b93226 to your computer and use it in GitHub Desktop.
ES6 Generators
'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