Skip to content

Instantly share code, notes, and snippets.

@philippgerbig
Last active September 30, 2016 20:33
Show Gist options
  • Save philippgerbig/7d1bdeb7f106e8a74c3a076db5de7e89 to your computer and use it in GitHub Desktop.
Save philippgerbig/7d1bdeb7f106e8a74c3a076db5de7e89 to your computer and use it in GitHub Desktop.
Generator function example with co and ajax request
import fetch from 'node-fetch';
// for use in browser you need to import fetch from fetch-polyfill
import co from 'co';
co(function *() {
const url = 'http://jsonplaceholder.typicode.com/posts/i';
const response = yield fetch(url);
const post = yield response.json();
const { title } = post;
console.log('Title:', title);
}).catch(err => console.error(err.stack));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment