Skip to content

Instantly share code, notes, and snippets.

@Xotabu4
Created June 7, 2019 17:42
Show Gist options
  • Save Xotabu4/9f42147f3aef100a4382d155bd2a7dc8 to your computer and use it in GitHub Desktop.
Save Xotabu4/9f42147f3aef100a4382d155bd2a7dc8 to your computer and use it in GitHub Desktop.
wait for everything, without browser.wait or driver.wait
async function waitFor(condition, timeout, poolInterval) {
const timeoutDeadline = new Date().getTime() + timeout;
let iterationRes;
do {
console.log('#', new Date().getTime(), timeoutDeadline);
if (new Date().getTime() > timeoutDeadline) {
let timeoutError = new Error("Wait timeout error!");
console.log(condition.toString())
throw timeoutError;
}
try {
iterationRes = await condition();
console.log(interationError);
} catch (interationError) {
lastErr = interationError;
iterationRes = false;
}
if (!iterationRes) {
await new Promise(r => setTimeout(r, poolInterval));
}
} while (!iterationRes);
}
waitFor(
async function () {
return Promise.resolve(true)
},
2000,
1000
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment