@tusss/ood
    Preparing search index...

    Class BatchExecutor<TOps>

    A utility class to queue operations and execute them in batches.

    Executing operations in batches of a specified capacity and flushing remaining items:

    const executor = new BatchExecutor<number>({
    capacity: 3,
    execute: async (batch) => {
    console.log("Executing batch:", batch);
    }
    });

    executor.add(1);
    executor.add(2);
    executor.add(3);

    if (executor.isFull) {
    await executor.execAndFlush(); // Logs: Executing batch: [1, 2, 3]
    }

    executor.add(4);
    if (!executor.isEmpty) {
    await executor.execAndFlush(); // Logs: Executing batch: [4]
    }

    Type Parameters

    • TOps

      The type of individual operations/items processed by the executor.

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    Properties

    capacity: number

    The maximum number of operations that can be held in a batch before it is considered full.

    100
    
    name: string

    The name identifying this batch executor instance.

    "batch-executor"
    

    Accessors

    • get isEmpty(): boolean

      Checks whether there are no operations currently queued in the batch.

      Returns boolean

    • get isFull(): boolean

      Checks whether the batch size has reached or exceeded the configured capacity.

      Returns boolean

    Methods

    • Triggers the execution of all currently queued operations and then clears the batch.

      Returns Promise<void>

      A promise that resolves when the execution is complete.