zenflow/composite-service

View on GitHub
src/util/onceAsyncTest.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { promisify } from "util";

const delay = promisify(setTimeout);

export async function onceAsyncTest(
  minimumInterval: number,
  test: () => Promise<boolean>
): Promise<void> {
  while (true) {
    const delayPromise = delay(minimumInterval);
    if (await test()) {
      return;
    }
    await delayPromise;
  }
}