Created
August 25, 2018 20:50
-
-
Save kerminz/3f96055d8ce799631b6bd267cdd6045a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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