A generic batch processing queue, implemented as a set. (So items are processed at most once per batch run.)

interface Batch<T> {
    add(item: T): void;
    delete(item: T): void;
    flush: (() => void);
    has(item: any): boolean;
    isEmpty(): boolean;
    isRunning(): boolean;
}

Type Parameters

  • T

    The type of items that will be in the batch

Properties

Methods

Properties

flush: (() => void)

Process the batch now by calling the processing function, unless the batch is empty or already running. If the processing function exits without fully emptying the batch (due to errors, time limits, etc.), another flush will be scheduled via the batch's scheduler (unless one is already scheduled).

Type declaration

    • (): void
    • Returns void

Methods

  • Add an item to the batch. Schedules the batch for processing if the batch was empty and is not already scheduled. (Does nothing if the item is already in the batch.)

    Parameters

    • item: T

    Returns void

  • Remove an item from the batch. (Does not affect the schedule.)

    Parameters

    • item: T

    Returns void

  • Is the item in the batch?

    Parameters

    • item: any

    Returns boolean

  • Is the batch processing function currently running?

    Returns boolean