summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/dom/fs/support/testHelpers.js
blob: 5cf47435c1a5008d322dcb8d78d49aa1f61cedc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
async function waitUntil(isWaitDone, untilMs, stepMs = 25) {
  const startMs = Date.now();

  return new Promise((resolve, reject) => {
      const areWeDoneYet = setInterval(async function() {
        if (await isWaitDone()) {
          clearInterval(areWeDoneYet);
          resolve();
        } else if (Date.now() > startMs + untilMs) {
          clearInterval(areWeDoneYet);
          reject(new Error("Timed out after " + untilMs + "ms"));
        }
      }, stepMs);
  });
}