Skip to content

Instantly share code, notes, and snippets.

@tario
Created November 29, 2016 17:25
Show Gist options
  • Save tario/6afb5a06a605b9e039cd45db96950ce1 to your computer and use it in GitHub Desktop.
Save tario/6afb5a06a605b9e039cd45db96950ce1 to your computer and use it in GitHub Desktop.
var q = require("q");
// crea una promise, que se resuelve despues de 1 segundo
var prm = function(name) {
console.log("promise " + name + " started");
return q.delay(1000)
.then(function() {
console.log("promise " + name + " resolved");
return name.length;
});
};
var z = q.async(function*() {
var x = yield prm("xxxx");
var y = yield prm("yyy");
return x + y;
});
z().then(function(result) {
console.log("result: " + result);
process.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment