Skip to content

Instantly share code, notes, and snippets.

@ccapndave
Created May 4, 2012 01:02
Show Gist options
  • Select an option

  • Save ccapndave/2590836 to your computer and use it in GitHub Desktop.

Select an option

Save ccapndave/2590836 to your computer and use it in GitHub Desktop.
// NOT WORKING VERSION
var populateUsers, deferreds, dfd, torch, _i, _len;
deferreds = [];
for (_i = 0, _len = results.length; _i < _len; _i++) {
torch = results[_i];
dfd = new $.Deferred();
torch.populateUsers(function(populatedTorch) {
return dfd.resolve();
});
deferreds.push(dfd.promise());
}
$.when.apply(null, deferreds).done(function() {
return console.log('DONE');
});
// WORKING VERSION
var deferreds, dfd, torch, _fn, _i, _len;
deferreds = [];
_fn = function(dfd) {
return torch.populateUsers(function(populatedTorch) {
return dfd.resolve();
});
};
for (_i = 0, _len = results.length; _i < _len; _i++) {
torch = results[_i];
dfd = new $.Deferred();
_fn(dfd);
deferreds.push(dfd.promise());
}
$.when.apply(null, deferreds).done(function() {
return console.log('DONE');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment