Created
November 12, 2014 19:25
-
-
Save mfbx9da4/d6e920693c0ac423a0c5 to your computer and use it in GitHub Desktop.
try to execute a callback for a while
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
var try = function (callback, terminal_case_callback, times, interval) { | |
var number_of_times_tried = 0; | |
times = times || 1000; | |
interval = interval || 5; | |
var _timeout_id = setInterval(function () { | |
callback(); | |
if (terminal_case_callback() || number_of_times_tried > times) { | |
clearInterval(_timeout_id); | |
} | |
}, interval) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment