AsyncLoop

An implementation of a loop for asynchronous functions.

Hierarchy

  • AsyncLoop

Index

Constructors

constructor

  • new AsyncLoop(iterations: number, _fn: function, _successCallback: function, offset?: number): AsyncLoop
  • Constroctor.

    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

Properties

index

index: number

iterations

iterations: number

Methods

breakLoop

  • breakLoop(): void
  • Break the loop and run the success callback.

    Returns void

executeNext

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

    Returns void

Static Run

  • Run(iterations: number, _fn: function, _successCallback: function, offset?: number): AsyncLoop
  • Helper function

    Parameters

    • iterations: number
    • _fn: function
    • _successCallback: function
        • (): void
        • Returns void

    • Optional offset: number

    Returns AsyncLoop

Static SyncAsyncForLoop

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

    constructor

    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 void

Generated using TypeDoc