Preparing search index...

    Function mapInChunks

    • Maps items to results one chunk at a time, yielding to the event loop between chunks. Results are concatenated in original order.

      The mapper receives a whole chunk and returns its mapped results, allowing per-chunk batch work. Use this for CPU-heavy transforms that would otherwise run as a single un-yielded .map over a large array.

      Type Parameters

      • T

        Input element type

      • R

        Output element type

      Parameters

      • items: readonly T[]

        Source array

      • mapper: (chunk: T[], chunkIndex: number) => R[] | Promise<R[]>

        Maps a chunk to its results

      • chunkSize: number = DEFAULT_CHUNK_SIZE

        Maximum chunk length; must be a positive integer. Defaults to DEFAULT_CHUNK_SIZE

      Returns Promise<R[]>

      Promise resolving to all mapped results in original order

      RangeError if chunkSize is not a positive integer