Class Chunker<T>

Collects items up to countLimit, calling writer before sizeLimit would be exceeded.

Remarks

Always call onIdle when done to ensure that the last writer call is made.

Type Parameters

  • T

    Type of items to be chunked

Hierarchy

  • Chunker

Constructors

  • Creates a new Chunker instance

    Type Parameters

    • T

      Type of items to be chunked

    Parameters

    • options: {
          countLimit: number;
          sizeLimit: number;
          sizer: SizerFunc<T>;
          writer: WriterFunc<T>;
      }

      Chunker options

      • countLimit: number

        number of pending items requiring that writer be called

      • sizeLimit: number

        user-defined size before which writer should be called

      • sizer: SizerFunc<T>

        function that returns user-defined size of an item

      • writer: WriterFunc<T>

        function that writes the pending items when sizeLimit or countLimit would be exceeded. This is not a mapper as it does not return a result at all. If the results need to be passed along, add them to an IterableQueueMapper for example.

    Returns Chunker<T>

Properties

_backgroundWriter: Promise<void>
_errors: Errors = []
_iterableQueue: IterableQueue<T> = ...
_pendingItems: T[] = []
_pendingSize: number = 0
_writer: WriterFunc<T>

Accessors

  • get errors(): Errors
  • Accumulated errors from background flushes

    Returns Errors

  • get pendingCount(): number
  • Number of items pending

    Returns number

  • get pendingSize(): number
  • Sum of the user-defined size of all pending items

    Returns number

Methods

  • Adds an item to the pending queue, flushing the queue before adding the item if the new item would cause the item limit or size limit to be exceeded.

    Parameters

    • item: T

      Item to be added to the queue

    Returns Promise<void>

  • Calls writer for any pending items and clears pending items queue.

    Returns Promise<void>

    Result from writer function or undefined if no items pending

  • Wait for all background writes to finish. MUST be called before exit to ensure no lost writes.

    Returns Promise<void>

Generated using TypeDoc