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.
19 lines
466 B
19 lines
466 B
2 years ago
|
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>, 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);
|
||
|
}
|
||
|
}
|