Skip to content

Instantly share code, notes, and snippets.

@mfbx9da4
Created November 12, 2014 19:25
Show Gist options
  • Save mfbx9da4/d6e920693c0ac423a0c5 to your computer and use it in GitHub Desktop.
Save mfbx9da4/d6e920693c0ac423a0c5 to your computer and use it in GitHub Desktop.
try to execute a callback for a while
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