Skip to content

Instantly share code, notes, and snippets.

@kennethlove
Created May 24, 2012 20:49
Show Gist options
  • Save kennethlove/2784153 to your computer and use it in GitHub Desktop.
Save kennethlove/2784153 to your computer and use it in GitHub Desktop.
Deferedorator
var Deferedorator = function(col, func) {
_.extend(this, Backbone.Events);
this.collection_ = col;
this.function_ = func;
};
Deferedorator.prototype.start = function() {
this.doItem_(0);
};
Deferedorator.prototype.doItem_ = function(i) {
_.defer(this.doFunction_, i);
};
Deferedorator.prototype.doFunction_ = function(i) {
var item = this.collection_[i];
this.function_(item);
if (!this.collection_[i+1]) {
this.trigger("finished");
return;
}
this.doItem_(i+1);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment