Skip to content

Instantly share code, notes, and snippets.

@sergiodxa
Last active August 29, 2015 14:21
Show Gist options
  • Save sergiodxa/122117a923f27a2a511d to your computer and use it in GitHub Desktop.
Save sergiodxa/122117a923f27a2a511d to your computer and use it in GitHub Desktop.
Generadores
import xhr from 'promised-xhr';
function* obtenerDatos () {
try {
const data = yield xhr.get('/api/resource');
const data2 = yield xhr.get(data.url);
return `${data2}!`;
} catch (error) {
throw error;
}
}
let iterador = obtenerDatos();
iterador.next().value
.then(data => iterador.next(data.body).value)
.then(data => iterador.next(data.body).value)
.then(data => console.log(data))
.catch(err => console.log(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment