Tweakr
    Preparing search index...

    Function waitFor

    • Waits for a condition function to return true or a promise that resolves to true.

      Polls the condition at a specified interval until it returns true or the timeout is reached, in which case an error is thrown.

      Type Parameters

      • T extends boolean

      Parameters

      • condition: () => T | Promise<T>

        A function returning a boolean or a promise that resolves to boolean.

      • options: WaitForOptions = {}

        Optional configuration for polling interval and timeout.

      Returns Promise<void>

      A promise that resolves when the condition becomes true.

      let ready = false;
      setTimeout(() => { ready = true }, 500);

      await waitFor(() => ready, { interval: 100, timeoutMs: 1000 });
      console.log("Condition met");

      Will throw an error if the condition is not met within the timeout.

      1.2.0