Files
react-test/packages/waterfall/waitUntil.mjs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

18 lines
411 B
JavaScript
Raw Permalink Normal View History

2025-12-12 14:26:25 +09:00
import sleep from './sleep.mjs';
export default async function waitUntil(test, options = {}) {
const { delay = 5e3, tries = -1 } = options;
const { predicate, result } = await test();
if (predicate) {
return result;
}
if (tries - 1 === 0) {
throw new Error('tries limit reached');
}
await sleep(delay);
return waitUntil(test, { ...options, tries: tries > 0 ? tries - 1 : tries });
}