• JMap.Util.asyncProcess

    Run the parameter function after one or multiple delays.

    You can cancel the repetition by running the function returned by asyncProcess

    Parameters

    • callback: (() => any)

      The function to run

        • (): any
        • Returns any

    • timeoutsInMilliseconds: number[]

      An array of delay in milliseconds

    Returns (() => void)

    a function that will cancel the process if called

      • (): void
      • Returns void

    Throws

    if callback is not a function, if timeoutsInMilliseconds is not a non-empty array of number

    Example

    // Print "Hello World" 4 times then cancel it before printing the last repetition
    const myHelloWorldFunction = () => console.log("Hello World")
    const stopProcessing = JMap.Util.asyncProcess(myHelloWorldFunction, [1000, 1000, 1000, 1000, 1000])
    setTimeout(() => stopProcessing(), 4100)