Skip to content

Instantly share code, notes, and snippets.

@benvinegar
Created July 30, 2012 18:12
Show Gist options
  • Save benvinegar/3208798 to your computer and use it in GitHub Desktop.
Save benvinegar/3208798 to your computer and use it in GitHub Desktop.
Chained defer
// Execute fn for each element in arr, releasing to the UI
// thread (via underscore's _.defer) between each execution
_.chainedDefer = (function () {
function next(arr, fn, scope) {
if (!arr.length)
return;
fn.call(scope, arr.shift());
_.chainedDefer(arr, fn, scope);
}
return function (arr, fn, scope) {
_.defer(function () {
next(arr, fn, scope);
});
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment