Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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