UNPKG

simple-in-memory-queue

Version:

A simple in-memory queue, for nodejs and the browser, with consumers for common usecases.

25 lines (24 loc) 890 B
/** * creates a queue with a consumer that consumes all items from it as soon as new items stop being added * * note * - produces one call to the consumer for all pushes to the queue that occurred within the delay period of eachother * * usecases * - waiting until all rapid activity stops to summarize the activity, before processing it * - for example: scroll events, mouse movements, typing, etc */ export declare const createQueueWithDebounceConsumer: <T>({ consumer, gap, }: { /** * the consumer to invoke with all of the events added to the queue queue, after debounce delay has expired */ consumer: ({ items }: { items: T[]; }) => void | Promise<void>; /** * the gap in time to wait between new events before calling the consumer */ gap: { milliseconds: number; }; }) => import("../queue/createQueue").Queue<T>;