@jiminp/tooltool
    Preparing search index...

    Function batchedForEach

    • Asynchronously iterate over an array in batches.

      • If batch_size > 0, the array is split into consecutive batches of up to batch_size elements and processed sequentially.
      • If batch_size === 0, the entire array is passed as a single batch (with index = 0).

      Type Parameters

      • T

      Parameters

      • arr: T[]

        The array to iterate over.

      • batch_size: number

        Items per batch. 0 means "use the entire array as one batch". Must be a non-negative safe integer.

      • fn: (batch: T[], index: number) => Promise<void>

        Async callback invoked for each batch.

        • batch: A slice of arr (entire arr when batch_size === 0).
        • index: Starting index of batch within arr (always 0 when batch_size === 0).

      Returns Promise<void>

      Resolves when all batches have been processed.

      If batch_size is negative or not a safe integer.

      // Two-element batches
      await batchedForEach([1,2,3,4,5], 2, async (batch, index) => {
      console.log(index, batch);
      });