Function sleepWhile

  • Sleep while function returns true

    Parameters

    • fn: (() => boolean | Promise<boolean>)

      Return true to continue

        • (): boolean | Promise<boolean>
        • Returns boolean | Promise<boolean>

    • checkInterval: number = 100

      Run function ever x milliseconds

    Returns Promise<void>

    Callback when sleep is over

    let loading = true;
    setTimeout(() => wait = false, 1000);
    await sleepWhile(() => loading); // Won't continue until loading flag is false