AsyncLoop

An implementation of a loop for asynchronous functions.

Hierarchy

  • AsyncLoop

Index

Constructors

constructor

Find examples in Playground
  • new AsyncLoop(iterations: number, func: function, successCallback: function, offset?: number): AsyncLoop
  • Constructor.

    Parameters

    • iterations: number

      the number of iterations.

    • func: function

      the function to run each iteration

    • successCallback: function

      the callback that will be called upon succesful execution

        • (): void
        • Returns void

    • Optional offset: number

      starting offset.

    Returns AsyncLoop

Properties

index

Find examples in Playground
index: number

Defines the current index of the loop.

iterations

Find examples in Playground
iterations: number

Defines the number of iterations for the loop

Methods

breakLoop

Find examples in Playground
  • breakLoop(): void
  • Break the loop and run the success callback.

    Returns void

executeNext

Find examples in Playground
  • executeNext(): void
  • Execute the next iteration. Must be called after the last iteration was finished.

    Returns void

Static Run

Find examples in Playground
  • Run(iterations: number, fn: function, successCallback: function, offset?: number): AsyncLoop
  • Create and run an async loop.

    Parameters

    • iterations: number

      the number of iterations.

    • fn: function

      the function to run each iteration

    • successCallback: function

      the callback that will be called upon succesful execution

        • (): void
        • Returns void

    • Optional offset: number

      starting offset.

    Returns AsyncLoop

    the created async loop object

Static SyncAsyncForLoop

Find examples in Playground
  • SyncAsyncForLoop(iterations: number, syncedIterations: number, fn: function, callback: function, breakFunction?: function, timeout?: number): AsyncLoop
  • A for-loop that will run a given number of iterations synchronous and the rest async.

    Parameters

    • iterations: number

      total number of iterations

    • syncedIterations: number

      number of synchronous iterations in each async iteration.

    • fn: function

      the function to call each iteration.

        • (iteration: number): void
        • Parameters

          • iteration: number

          Returns void

    • callback: function

      a success call back that will be called when iterating stops.

        • (): void
        • Returns void

    • Optional breakFunction: function

      a break condition (optional)

        • (): boolean
        • Returns boolean

    • Optional timeout: number

      timeout settings for the setTimeout function. default - 0.

    Returns AsyncLoop

    the created async loop object

Generated using TypeDoc