Last active
October 27, 2015 17:22
-
-
Save rnaffer/fedc313dad44573c6b29 to your computer and use it in GitHub Desktop.
Uso de nuevas características de javascript (ES6) para hacer operaciones asíncronas de forma estructurada.
This file contains 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
// El uso de generadores aún no está estandarizado. 25/10/2015 | |
// Requiere generators.js | |
// El asterisco '*' lo define como generador | |
// yield detiene el procedimiento hasta que pueda continuar | |
// Librerias: bluebird para frontend -usado en el ejemplo-, co para bakcend node.js, q para angular | |
Promise.coroutine(function* () { | |
var user = yield $.get('user.json'); | |
// Do stuff with user | |
var posts = yield $.get( 'posts.json?id=' + user.id ); | |
// Do stuff with posts | |
var comments = yield $.get( 'comments.json?post_id=' + post.id ); | |
// Do stuff with comments | |
})().catch(function( errs ) { | |
// Do stuff with errors | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment