Created
July 30, 2012 18:12
-
-
Save benvinegar/3208798 to your computer and use it in GitHub Desktop.
Chained defer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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