Skip to content

Instantly share code, notes, and snippets.

@grgur
grgur / async-generator.js
Last active September 12, 2015 22:11
Demo of async/await with ES6 generators
function makeRequest(url) {
fetch(url)
.then(response => response.json())
.then(json => it.next(json))
.catch(error => console.error('Somthing shit the bed', error));
}
function *syncRequests() {
const redditUrl = 'https://www.reddit.com/controversial.json?count=1&limit=2';
const page1 = yield makeRequest(redditUrl);