• Waits until the given predicate evaluates to true.

    Parameters

    • predicate: (() => boolean)

      The predicate that should be evaluated.

        • (): boolean
        • Returns boolean

    • Optional options: {
          timeout: number;
      }

      Optional options.

      • timeout: number

        The number of milliseconds to wait before timing out.

    Returns Promise<void>

    A promise that resolves when the predicate evaluates to true.

    Example

    const a = atom(0, { name: "a" });
    let foo = 0;

    waitTrue(() => a.value > 3).then(() => {
    foo++;
    });

    a.value = 2; // foo = 0
    a.value = 3; // foo = 0
    a.value = 4; // foo = 1