Last active
September 4, 2022 23:22
-
-
Save refracta/c3e33f4e797603f8aa766504414a6986 to your computer and use it in GitHub Desktop.
waitFor.js
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
function waitFor(checkFunction, checkDelay = 100) { | |
return new Promise(resolve => { | |
let i = setInterval(_ => { | |
try { | |
let check = checkFunction(); | |
check ? clearInterval(i) || resolve(check) : void 0 | |
} catch (e) {} | |
}, checkDelay); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment