Skip to content

Instantly share code, notes, and snippets.

@mosfet1kg
Created July 31, 2015 10:10
Show Gist options
  • Select an option

  • Save mosfet1kg/64e7280b25b014793c6f to your computer and use it in GitHub Desktop.

Select an option

Save mosfet1kg/64e7280b25b014793c6f to your computer and use it in GitHub Desktop.
Q + Closure
var Q = require('q');
var funcs = [];
for (var i = 0; i < 3; i++) {
funcs.push((function(m){
return function() {
var d = Q.defer();
console.log("My value: " + m);
d.resolve();
return d.promise;
};
})(i));
}
var result = Q();
funcs.forEach(function(f){
result = result.then(f);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment