Skip to content

Instantly share code, notes, and snippets.

@thegrandpoobah
Created May 5, 2011 14:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thegrandpoobah/957146 to your computer and use it in GitHub Desktop.
Save thegrandpoobah/957146 to your computer and use it in GitHub Desktop.
Retry mixin for Underscore.js
_.mixin({
// Polls condition indefinitely every N milliseconds and executes
// a function once the condition has passed.
retry: function(func, cond, wait) {
var args = slice.call(arguments, 3);
if (cond()) {
func.apply(this, args);
} else {
_.delay.apply(this, [_.retry, wait, func, cond, wait].concat(args));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment