Created
May 5, 2011 14:34
-
-
Save thegrandpoobah/957146 to your computer and use it in GitHub Desktop.
Retry mixin for Underscore.js
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
_.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