• Returns a Promise that completes when the test function returns true, or after the timeout has elapsed

    Parameters

    • func: (() => boolean)

      a function that returns true when the test condition is met

        • (): boolean
        • Returns boolean

    • timeoutFunc: (() => void)

      the function called after a timeout

        • (): void
        • Returns void

    • timeoutMs: number = 2000

      miliseconds to wait for the test function to return true before timing out

    Returns Promise<void>

    let test = 1;
    const trueFunc = () => {test == 1}
    const falseFunc = () => {test == 2}
    const timeoutFunc = () => {console.warn('timeout!')}
    waitForConditionAsync(trueFunc, timeoutFunc, 3000); // returns right away
    waitForConditionAsync(falseFunc, timeoutFunc, 3000); // returns in 3s and console.warn('timeout!')