Skip to content

Instantly share code, notes, and snippets.

@kerminz
Created August 25, 2018 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kerminz/3f96055d8ce799631b6bd267cdd6045a to your computer and use it in GitHub Desktop.
Save kerminz/3f96055d8ce799631b6bd267cdd6045a to your computer and use it in GitHub Desktop.
function whenConditionIsMet(condition, callback, interval, timeout) {
if (typeof interval !== "number") {
interval = 150;
}
var runInt = setInterval(function() {
try {
if (condition() === true) {
callback();
clearInterval(runInt);
}
} catch(e) {
}
}, interval);
if (typeof timeout === "number") {
setTimeout(function() {
clearInterval(runInt)
}, timeout);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment