Skip to content

Instantly share code, notes, and snippets.

@technix
technix / promise-wait.js
Last active March 10, 2024 14:22
Wait for variable to become true - in promise
window.testVar = null;
function waitForCondition (variable) {
function waitFor(result) {
if (result) {
return result;
}
return new Promise((resolve) => setTimeout(resolve, 100))
.then(() => Promise.resolve(window[variable]))
.then((res) => waitFor(res));