diff --git a/packages/core/src/utils.js b/packages/core/src/utils.js index 3e09859ac..3a3048e65 100644 --- a/packages/core/src/utils.js +++ b/packages/core/src/utils.js @@ -100,14 +100,16 @@ export function waitFor(predicate, options) { ? { timeout: options } : (options || {}); return generatePromise(async function* check(start, done) { - if (timeout && Date.now() - start >= timeout) { - throw new Error(`Timeout of ${timeout}ms exceeded.`); - } else if (!predicate()) { - yield new Promise(r => setTimeout(r, poll)); - return yield* check(start); - } else if (idle && !done) { - yield new Promise(r => setTimeout(r, idle)); - return yield* check(start, true); + while (true) { + if (timeout && Date.now() - start >= timeout) { + throw new Error(`Timeout of ${timeout}ms exceeded.`); + } else if (!predicate()) { + yield new Promise(r => setTimeout(r, poll, (done = false))); + } else if (idle && !done) { + yield new Promise(r => setTimeout(r, idle, (done = true))); + } else { + return; + } } }(Date.now())); }