Skip to content

Instantly share code, notes, and snippets.

@refracta
Last active September 4, 2022 23:22
Show Gist options
  • Save refracta/c3e33f4e797603f8aa766504414a6986 to your computer and use it in GitHub Desktop.
Save refracta/c3e33f4e797603f8aa766504414a6986 to your computer and use it in GitHub Desktop.
waitFor.js
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