Class BatchTask<T>

Non-blocking iterative task, using the event loop to divide the iteration into smaller batches and schedule them for deferred execution.

The constructor accepts a list of input values, a function to process them, and an object describing the strategy used to divide the task into batches.

The batching strategies are the following:

  • iterations: the batches contain a fixed amount of iterations,
  • milliseconds: the batches take a fixed amount of time to complete.

Returning false in the processing function stops the iteration, similarly to what happens when using a break statement in a regular loop.

Type Parameters

  • T

Hierarchy

  • BatchTask

Constructors

  • Type Parameters

    • T

    Parameters

    • values: T[]
    • callback: ((value) => unknown)
        • (value): unknown
        • Parameters

          • value: T

          Returns unknown

    • options: BatchTaskOptions

    Returns BatchTask<T>

Properties

callback: ((value) => unknown)

Type declaration

    • (value): unknown
    • Parameters

      • value: T

      Returns unknown

canceled: boolean = false
completed: boolean = false
done: Promise<void> = ...

Promise resolved as soon as the task terminates successfully, and rejected in case the task is canceled from the outside.

values: T[]

Methods

  • Cancels the execution of this background task.

    Returns void

  • Whether or not the task execution was canceled.

    Returns boolean

  • Whether or not the task has successfully terminated its execution.

    Returns boolean

  • Applies the processing function to the input values. The task is divided into batches containing a fixed amount of iterations.

    Parameters

    • startIndex: number
    • amount: number

    Returns void

  • Applies the operator function to the input values. The task is divided into batches processed within a fixed amount of time.

    Parameters

    • startIndex: number
    • amount: number

    Returns void

  • Applies the processing function to a single value, and resolves the done promise when the task terminates.

    Parameters

    • index: number

    Returns boolean

  • Parameters

    • _: Error

    Returns void

Generated using TypeDoc