You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gristlabs_grist-core/test/server/wait.ts

19 lines
471 B

import * as bluebird from 'bluebird';
/**
* Wait some time for a check to pass. Allow a pause between checks.
*/
export async function waitForIt(check: () => Promise<void>|void, maxWaitMs: number,
stepWaitMs: number = 1000) {
const start = Date.now();
for (;;) {
try {
await check();
return;
} catch (e) {
if (Date.now() - start > maxWaitMs) { throw e; }
}
await bluebird.delay(stepWaitMs);
}
}