• Create a batch processing queue from the given processing loop and scheduling function.

    Type Parameters

    • T

      The type of items that will be in the batch

    Parameters

    • process: ((items: Set<T>) => void)

      A function taking a set of items. It should remove items from the set, usually before processing them. (So that the batch won't perpetually block on that item in case of a persistent error.) If the processing function doesn't remove all items from the set, another processing pass will be done later. (This allows you to rate-limit processing, so as not to hog the current thread.)

        • (items: Set<T>): void
        • Parameters

          • items: Set<T>

          Returns void

    • Optional sched: ((cb: (() => unknown)) => unknown)

      A single-argument scheduling function (like requestAnimationFrame, setImmediate, or queueMicrotask). The batch will call it from time to time with a single callback. The scheduling function should then arrange for that callback to be invoked once at some future point, when it is the desired time for pending items to be processed. If no function is given (or it's undefined/null), defer is used.

        • (cb: (() => unknown)): unknown
        • Parameters

          • cb: (() => unknown)
              • (): unknown
              • Returns unknown

          Returns unknown

    Returns Batch<T>

    a Batch that items can be added to for later processing.