@tanstack/solid-pacer 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/cjs/async-queuer/createAsyncQueuer.cjs +5 -3
  2. package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -1
  3. package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +23 -16
  4. package/dist/cjs/batcher/createBatcher.cjs +58 -0
  5. package/dist/cjs/batcher/createBatcher.cjs.map +1 -0
  6. package/dist/cjs/batcher/createBatcher.d.cts +76 -0
  7. package/dist/cjs/batcher/index.cjs +12 -0
  8. package/dist/cjs/batcher/index.cjs.map +1 -0
  9. package/dist/cjs/batcher/index.d.cts +2 -0
  10. package/dist/cjs/index.cjs +2 -0
  11. package/dist/cjs/index.cjs.map +1 -1
  12. package/dist/cjs/index.d.cts +1 -0
  13. package/dist/cjs/queuer/createQueuer.cjs +2 -2
  14. package/dist/cjs/queuer/createQueuer.cjs.map +1 -1
  15. package/dist/cjs/queuer/createQueuer.d.cts +27 -21
  16. package/dist/esm/async-queuer/createAsyncQueuer.d.ts +23 -16
  17. package/dist/esm/async-queuer/createAsyncQueuer.js +5 -3
  18. package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -1
  19. package/dist/esm/batcher/createBatcher.d.ts +76 -0
  20. package/dist/esm/batcher/createBatcher.js +58 -0
  21. package/dist/esm/batcher/createBatcher.js.map +1 -0
  22. package/dist/esm/batcher/index.d.ts +2 -0
  23. package/dist/esm/batcher/index.js +6 -0
  24. package/dist/esm/batcher/index.js.map +1 -0
  25. package/dist/esm/index.d.ts +1 -0
  26. package/dist/esm/index.js +2 -0
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/queuer/createQueuer.d.ts +27 -21
  29. package/dist/esm/queuer/createQueuer.js +2 -2
  30. package/dist/esm/queuer/createQueuer.js.map +1 -1
  31. package/package.json +12 -2
  32. package/src/async-queuer/createAsyncQueuer.ts +35 -28
  33. package/src/batcher/createBatcher.ts +152 -0
  34. package/src/batcher/index.ts +3 -0
  35. package/src/index.ts +3 -0
  36. package/src/queuer/createQueuer.ts +28 -21
@@ -1 +1 @@
1
- {"version":3,"file":"createAsyncQueuer.js","sources":["../../../src/async-queuer/createAsyncQueuer.ts"],"sourcesContent":["import { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type {\n AsyncQueuerFn,\n AsyncQueuerOptions,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface SolidAsyncQueuer<TFn extends AsyncQueuerFn>\n extends Omit<\n AsyncQueuer<TFn>,\n | 'getActiveItems'\n | 'getAllItems'\n | 'getErrorCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getPeek'\n | 'getPendingItems'\n | 'getRejectionCount'\n | 'getSettledCount'\n | 'getSize'\n | 'getSuccessCount'\n > {\n /**\n * Signal version of `getActiveItems`\n */\n activeItems: Accessor<Array<TFn>>\n /**\n * Signal version of `getAllItems`\n */\n allItems: Accessor<Array<TFn>>\n /**\n * Signal version of `getErrorCount`\n */\n errorCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsFull`\n */\n isFull: Accessor<boolean>\n /**\n * Signal version of `getIsIdle`\n */\n isIdle: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getPeek`\n */\n peek: Accessor<TFn | undefined>\n /**\n * Signal version of `getPendingItems`\n */\n pendingItems: Accessor<Array<TFn>>\n /**\n * Signal version of `getRejectionCount`\n */\n rejectionCount: Accessor<number>\n /**\n * Signal version of `getSettledCount`\n */\n settledCount: Accessor<number>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n /**\n * Signal version of `getSuccessCount`\n */\n successCount: Accessor<number>\n}\n\n/**\n * A lower-level Solid hook that creates an `AsyncQueuer` instance for managing an async queue of items.\n *\n * Features:\n * - Priority queue support via getPriority option\n * - Configurable concurrency limit\n * - Task success/error/completion callbacks\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Pause/resume task processing\n * - Task cancellation\n * - Item expiration to clear stale items from the queue\n *\n * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,\n * the next pending task is processed if below the concurrency limit.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and queuer instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncQueuer instance\n *\n * @example\n * ```tsx\n * // Basic async queuer for API requests\n * const asyncQueuer = createAsyncQueuer({\n * initialItems: [],\n * concurrency: 2,\n * maxSize: 100,\n * started: false,\n * onSuccess: (result) => {\n * console.log('Item processed:', result);\n * },\n * onError: (error) => {\n * console.error('Processing failed:', error);\n * }\n * });\n *\n * // Add items to queue\n * asyncQueuer.addItem(newItem);\n *\n * // Start processing\n * asyncQueuer.start();\n * ```\n */\nexport function createAsyncQueuer<TFn extends AsyncQueuerFn>(\n initialOptions: AsyncQueuerOptions<TFn> = {},\n): SolidAsyncQueuer<TFn> {\n const asyncQueuer = new AsyncQueuer<TFn>(initialOptions)\n\n const [successCount, setSuccessCount] = createSignal(\n asyncQueuer.getSuccessCount(),\n )\n const [errorCount, setErrorCount] = createSignal(asyncQueuer.getErrorCount())\n const [settledCount, setSettledCount] = createSignal(\n asyncQueuer.getSettledCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n asyncQueuer.getRejectionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(asyncQueuer.getIsEmpty())\n const [isFull, setIsFull] = createSignal(asyncQueuer.getIsFull())\n const [isIdle, setIsIdle] = createSignal(asyncQueuer.getIsIdle())\n const [isRunning, setIsRunning] = createSignal(asyncQueuer.getIsRunning())\n const [allItems, setAllItems] = createSignal<Array<TFn>>(\n asyncQueuer.getAllItems(),\n )\n const [activeItems, setActiveItems] = createSignal<Array<TFn>>(\n asyncQueuer.getActiveItems(),\n )\n const [pendingItems, setPendingItems] = createSignal<Array<TFn>>(\n asyncQueuer.getPendingItems(),\n )\n const [peek, setPeek] = createSignal<TFn | undefined>(asyncQueuer.getPeek())\n const [size, setSize] = createSignal(asyncQueuer.getSize())\n\n asyncQueuer.setOptions({\n onItemsChange: (queuer) => {\n setActiveItems(queuer.getActiveItems())\n setAllItems(queuer.getAllItems())\n setErrorCount(queuer.getErrorCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setPeek(() => queuer.getPeek())\n setPendingItems(queuer.getPendingItems())\n setRejectionCount(queuer.getRejectionCount())\n setSettledCount(queuer.getSettledCount())\n setSize(queuer.getSize())\n setSuccessCount(queuer.getSuccessCount())\n initialOptions.onItemsChange?.(queuer)\n },\n onIsRunningChange: (queuer) => {\n setIsRunning(queuer.getIsRunning())\n setIsIdle(queuer.getIsIdle())\n initialOptions.onIsRunningChange?.(queuer)\n },\n onReject: (item, queuer) => {\n setRejectionCount(queuer.getRejectionCount())\n initialOptions.onReject?.(item, queuer)\n },\n })\n\n return {\n ...bindInstanceMethods(asyncQueuer),\n activeItems,\n allItems,\n errorCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n peek,\n pendingItems,\n rejectionCount,\n settledCount,\n size,\n successCount,\n } as SolidAsyncQueuer<TFn>\n}\n"],"names":[],"mappings":";;;AA6HgB,SAAA,kBACd,iBAA0C,IACnB;AACjB,QAAA,cAAc,IAAI,YAAiB,cAAc;AAEjD,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,YAAY,gBAAgB;AAAA,EAC9B;AACA,QAAM,CAAC,YAAY,aAAa,IAAI,aAAa,YAAY,eAAe;AACtE,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,YAAY,gBAAgB;AAAA,EAC9B;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,kBAAkB;AAAA,EAChC;AACA,QAAM,CAAC,SAAS,UAAU,IAAI,aAAa,YAAY,YAAY;AACnE,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,YAAY,WAAW;AAChE,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,YAAY,WAAW;AAChE,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,YAAY,cAAc;AACnE,QAAA,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,YAAY,YAAY;AAAA,EAC1B;AACM,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,YAAY,eAAe;AAAA,EAC7B;AACM,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,YAAY,gBAAgB;AAAA,EAC9B;AACA,QAAM,CAAC,MAAM,OAAO,IAAI,aAA8B,YAAY,SAAS;AAC3E,QAAM,CAAC,MAAM,OAAO,IAAI,aAAa,YAAY,SAAS;AAE1D,cAAY,WAAW;AAAA,IACrB,eAAe,CAAC,WAAW;;AACV,qBAAA,OAAO,gBAAgB;AAC1B,kBAAA,OAAO,aAAa;AAClB,oBAAA,OAAO,eAAe;AACzB,iBAAA,OAAO,YAAY;AACpB,gBAAA,OAAO,WAAW;AAClB,gBAAA,OAAO,WAAW;AACpB,cAAA,MAAM,OAAO,SAAS;AACd,sBAAA,OAAO,iBAAiB;AACtB,wBAAA,OAAO,mBAAmB;AAC5B,sBAAA,OAAO,iBAAiB;AAChC,cAAA,OAAO,SAAS;AACR,sBAAA,OAAO,iBAAiB;AACxC,2BAAe,kBAAf,wCAA+B;AAAA,IACjC;AAAA,IACA,mBAAmB,CAAC,WAAW;;AAChB,mBAAA,OAAO,cAAc;AACxB,gBAAA,OAAO,WAAW;AAC5B,2BAAe,sBAAf,wCAAmC;AAAA,IACrC;AAAA,IACA,UAAU,CAAC,MAAM,WAAW;;AACR,wBAAA,OAAO,mBAAmB;AAC7B,2BAAA,aAAA,wCAAW,MAAM;AAAA,IAAM;AAAA,EACxC,CACD;AAEM,SAAA;AAAA,IACL,GAAG,oBAAoB,WAAW;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"createAsyncQueuer.js","sources":["../../../src/async-queuer/createAsyncQueuer.ts"],"sourcesContent":["import { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AsyncQueuerOptions } from '@tanstack/pacer/async-queuer'\n\nexport interface SolidAsyncQueuer<TValue>\n extends Omit<\n AsyncQueuer<TValue>,\n | 'getActiveItems'\n | 'getAllItems'\n | 'getErrorCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getPeek'\n | 'getPendingItems'\n | 'getRejectionCount'\n | 'getSettledCount'\n | 'getSize'\n | 'getSuccessCount'\n > {\n /**\n * Signal version of `getActiveItems`\n */\n activeItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getAllItems`\n */\n allItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getErrorCount`\n */\n errorCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsFull`\n */\n isFull: Accessor<boolean>\n /**\n * Signal version of `getIsIdle`\n */\n isIdle: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getPeek`\n */\n peek: Accessor<TValue | undefined>\n /**\n * Signal version of `getPendingItems`\n */\n pendingItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getRejectionCount`\n */\n rejectionCount: Accessor<number>\n /**\n * Signal version of `getSettledCount`\n */\n settledCount: Accessor<number>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n /**\n * Signal version of `getSuccessCount`\n */\n successCount: Accessor<number>\n}\n\n/**\n * Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Priority queueing via `getPriority` or item `priority` property\n * - Configurable concurrency limit\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Pause/resume processing\n * - Task cancellation\n * - Item expiration\n * - Lifecycle callbacks for success, error, settled, items change, etc.\n * - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,\n * the next pending task is processed if the concurrency limit allows.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and queuer instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncQueuer instance\n *\n * Example usage:\n * ```tsx\n * // Basic async queuer for API requests\n * const asyncQueuer = createAsyncQueuer(async (item) => {\n * // process item\n * return await fetchData(item);\n * }, {\n * initialItems: [],\n * concurrency: 2,\n * maxSize: 100,\n * started: false,\n * onSuccess: (result) => {\n * console.log('Item processed:', result);\n * },\n * onError: (error) => {\n * console.error('Processing failed:', error);\n * }\n * });\n *\n * // Add items to queue\n * asyncQueuer.addItem(newItem);\n *\n * // Start processing\n * asyncQueuer.start();\n *\n * // Use Solid signals in your UI\n * const pending = asyncQueuer.pendingItems();\n * ```\n */\nexport function createAsyncQueuer<TValue>(\n fn: (value: TValue) => Promise<any>,\n initialOptions: AsyncQueuerOptions<TValue> = {},\n): SolidAsyncQueuer<TValue> {\n const asyncQueuer = new AsyncQueuer<TValue>(fn, initialOptions)\n\n const [successCount, setSuccessCount] = createSignal(\n asyncQueuer.getSuccessCount(),\n )\n const [errorCount, setErrorCount] = createSignal(asyncQueuer.getErrorCount())\n const [settledCount, setSettledCount] = createSignal(\n asyncQueuer.getSettledCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n asyncQueuer.getRejectionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(asyncQueuer.getIsEmpty())\n const [isFull, setIsFull] = createSignal(asyncQueuer.getIsFull())\n const [isIdle, setIsIdle] = createSignal(asyncQueuer.getIsIdle())\n const [isRunning, setIsRunning] = createSignal(asyncQueuer.getIsRunning())\n const [allItems, setAllItems] = createSignal<Array<TValue>>(\n asyncQueuer.getAllItems(),\n )\n const [activeItems, setActiveItems] = createSignal<Array<TValue>>(\n asyncQueuer.getActiveItems(),\n )\n const [pendingItems, setPendingItems] = createSignal<Array<TValue>>(\n asyncQueuer.getPendingItems(),\n )\n const [peek, setPeek] = createSignal<TValue | undefined>(\n asyncQueuer.getPeek(),\n )\n const [size, setSize] = createSignal(asyncQueuer.getSize())\n\n asyncQueuer.setOptions({\n onItemsChange: (queuer) => {\n setActiveItems(queuer.getActiveItems())\n setAllItems(queuer.getAllItems())\n setErrorCount(queuer.getErrorCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setPeek(() => queuer.getPeek())\n setPendingItems(queuer.getPendingItems())\n setRejectionCount(queuer.getRejectionCount())\n setSettledCount(queuer.getSettledCount())\n setSize(queuer.getSize())\n setSuccessCount(queuer.getSuccessCount())\n initialOptions.onItemsChange?.(queuer)\n },\n onIsRunningChange: (queuer) => {\n setIsRunning(queuer.getIsRunning())\n setIsIdle(queuer.getIsIdle())\n initialOptions.onIsRunningChange?.(queuer)\n },\n onReject: (item, queuer) => {\n setRejectionCount(queuer.getRejectionCount())\n initialOptions.onReject?.(item, queuer)\n },\n })\n\n return {\n ...bindInstanceMethods(asyncQueuer),\n activeItems,\n allItems,\n errorCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n peek,\n pendingItems,\n rejectionCount,\n settledCount,\n size,\n successCount,\n } as SolidAsyncQueuer<TValue>\n}\n"],"names":[],"mappings":";;;AAiIO,SAAS,kBACd,IACA,iBAA6C,IACnB;AAC1B,QAAM,cAAc,IAAI,YAAoB,IAAI,cAAc;AAExD,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,YAAY,gBAAgB;AAAA,EAC9B;AACA,QAAM,CAAC,YAAY,aAAa,IAAI,aAAa,YAAY,eAAe;AACtE,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,YAAY,gBAAgB;AAAA,EAC9B;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,kBAAkB;AAAA,EAChC;AACA,QAAM,CAAC,SAAS,UAAU,IAAI,aAAa,YAAY,YAAY;AACnE,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,YAAY,WAAW;AAChE,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,YAAY,WAAW;AAChE,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,YAAY,cAAc;AACnE,QAAA,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,YAAY,YAAY;AAAA,EAC1B;AACM,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,YAAY,eAAe;AAAA,EAC7B;AACM,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,YAAY,gBAAgB;AAAA,EAC9B;AACM,QAAA,CAAC,MAAM,OAAO,IAAI;AAAA,IACtB,YAAY,QAAQ;AAAA,EACtB;AACA,QAAM,CAAC,MAAM,OAAO,IAAI,aAAa,YAAY,SAAS;AAE1D,cAAY,WAAW;AAAA,IACrB,eAAe,CAAC,WAAW;;AACV,qBAAA,OAAO,gBAAgB;AAC1B,kBAAA,OAAO,aAAa;AAClB,oBAAA,OAAO,eAAe;AACzB,iBAAA,OAAO,YAAY;AACpB,gBAAA,OAAO,WAAW;AAClB,gBAAA,OAAO,WAAW;AACpB,cAAA,MAAM,OAAO,SAAS;AACd,sBAAA,OAAO,iBAAiB;AACtB,wBAAA,OAAO,mBAAmB;AAC5B,sBAAA,OAAO,iBAAiB;AAChC,cAAA,OAAO,SAAS;AACR,sBAAA,OAAO,iBAAiB;AACxC,2BAAe,kBAAf,wCAA+B;AAAA,IACjC;AAAA,IACA,mBAAmB,CAAC,WAAW;;AAChB,mBAAA,OAAO,cAAc;AACxB,gBAAA,OAAO,WAAW;AAC5B,2BAAe,sBAAf,wCAAmC;AAAA,IACrC;AAAA,IACA,UAAU,CAAC,MAAM,WAAW;;AACR,wBAAA,OAAO,mBAAmB;AAC7B,2BAAA,aAAA,wCAAW,MAAM;AAAA,IAAM;AAAA,EACxC,CACD;AAEM,SAAA;AAAA,IACL,GAAG,oBAAoB,WAAW;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -0,0 +1,76 @@
1
+ import { Batcher, BatcherOptions } from '@tanstack/pacer/batcher';
2
+ import { Accessor } from 'solid-js';
3
+ export interface SolidBatcher<TValue> extends Omit<Batcher<TValue>, 'getAllItems' | 'getBatchExecutionCount' | 'getIsEmpty' | 'getIsRunning' | 'getItemExecutionCount' | 'getSize'> {
4
+ /**
5
+ * Signal version of `getAllItems`
6
+ */
7
+ allItems: Accessor<Array<TValue>>;
8
+ /**
9
+ * Signal version of `getBatchExecutionCount`
10
+ */
11
+ batchExecutionCount: Accessor<number>;
12
+ /**
13
+ * Signal version of `getIsEmpty`
14
+ */
15
+ isEmpty: Accessor<boolean>;
16
+ /**
17
+ * Signal version of `getIsRunning`
18
+ */
19
+ isRunning: Accessor<boolean>;
20
+ /**
21
+ * Signal version of `getItemExecutionCount`
22
+ */
23
+ itemExecutionCount: Accessor<number>;
24
+ /**
25
+ * Signal version of `getSize`
26
+ */
27
+ size: Accessor<number>;
28
+ }
29
+ /**
30
+ * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.
31
+ *
32
+ * Features:
33
+ * - Batch processing of items using the provided `fn` function
34
+ * - Configurable batch size and wait time
35
+ * - Custom batch processing logic via getShouldExecute
36
+ * - Event callbacks for monitoring batch operations
37
+ * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
38
+ *
39
+ * The batcher collects items and processes them in batches based on:
40
+ * - Maximum batch size
41
+ * - Time-based batching (process after X milliseconds)
42
+ * - Custom batch processing logic via getShouldExecute
43
+ *
44
+ * Example usage:
45
+ * ```tsx
46
+ * const batcher = createBatcher(
47
+ * (items) => {
48
+ * // Process batch of items
49
+ * console.log('Processing batch:', items);
50
+ * },
51
+ * {
52
+ * maxSize: 5,
53
+ * wait: 2000,
54
+ * onExecute: (batcher) => console.log('Batch executed'),
55
+ * getShouldExecute: (items) => items.length >= 3
56
+ * }
57
+ * );
58
+ *
59
+ * // Add items to batch
60
+ * batcher.addItem('task1');
61
+ * batcher.addItem('task2');
62
+ *
63
+ * // Control the batcher
64
+ * batcher.stop(); // Pause processing
65
+ * batcher.start(); // Resume processing
66
+ *
67
+ * // Access batcher state via signals
68
+ * console.log('Items:', batcher.allItems());
69
+ * console.log('Size:', batcher.size());
70
+ * console.log('Is empty:', batcher.isEmpty());
71
+ * console.log('Is running:', batcher.isRunning());
72
+ * console.log('Batch count:', batcher.batchExecutionCount());
73
+ * console.log('Item count:', batcher.itemExecutionCount());
74
+ * ```
75
+ */
76
+ export declare function createBatcher<TValue>(fn: (items: Array<TValue>) => void, initialOptions?: BatcherOptions<TValue>): SolidBatcher<TValue>;
@@ -0,0 +1,58 @@
1
+ import { Batcher } from "@tanstack/pacer/batcher";
2
+ import { createSignal } from "solid-js";
3
+ import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
+ function createBatcher(fn, initialOptions = {}) {
5
+ const batcher = bindInstanceMethods(new Batcher(fn, initialOptions));
6
+ const [allItems, setAllItems] = createSignal(
7
+ batcher.getAllItems()
8
+ );
9
+ const [batchExecutionCount, setBatchExecutionCount] = createSignal(
10
+ batcher.getBatchExecutionCount()
11
+ );
12
+ const [itemExecutionCount, setItemExecutionCount] = createSignal(
13
+ batcher.getItemExecutionCount()
14
+ );
15
+ const [isEmpty, setIsEmpty] = createSignal(batcher.getIsEmpty());
16
+ const [isRunning, setIsRunning] = createSignal(batcher.getIsRunning());
17
+ const [size, setSize] = createSignal(batcher.getSize());
18
+ function setOptions(newOptions) {
19
+ batcher.setOptions({
20
+ ...newOptions,
21
+ onItemsChange: (batcher2) => {
22
+ setAllItems(batcher2.getAllItems());
23
+ setBatchExecutionCount(batcher2.getBatchExecutionCount());
24
+ setItemExecutionCount(batcher2.getItemExecutionCount());
25
+ setIsEmpty(batcher2.getIsEmpty());
26
+ setSize(batcher2.getSize());
27
+ const onItemsChange = newOptions.onItemsChange ?? initialOptions.onItemsChange;
28
+ onItemsChange == null ? void 0 : onItemsChange(batcher2);
29
+ },
30
+ onExecute: (batcher2) => {
31
+ setBatchExecutionCount(batcher2.getBatchExecutionCount());
32
+ setItemExecutionCount(batcher2.getItemExecutionCount());
33
+ const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
34
+ onExecute == null ? void 0 : onExecute(batcher2);
35
+ },
36
+ onIsRunningChange: (batcher2) => {
37
+ setIsRunning(batcher2.getIsRunning());
38
+ const onIsRunningChange = newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange;
39
+ onIsRunningChange == null ? void 0 : onIsRunningChange(batcher2);
40
+ }
41
+ });
42
+ }
43
+ setOptions(initialOptions);
44
+ return {
45
+ ...batcher,
46
+ allItems,
47
+ batchExecutionCount,
48
+ isEmpty,
49
+ isRunning,
50
+ itemExecutionCount,
51
+ size,
52
+ setOptions
53
+ };
54
+ }
55
+ export {
56
+ createBatcher
57
+ };
58
+ //# sourceMappingURL=createBatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBatcher.js","sources":["../../../src/batcher/createBatcher.ts"],"sourcesContent":["import { Batcher } from '@tanstack/pacer/batcher'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { BatcherOptions } from '@tanstack/pacer/batcher'\n\nexport interface SolidBatcher<TValue>\n extends Omit<\n Batcher<TValue>,\n | 'getAllItems'\n | 'getBatchExecutionCount'\n | 'getIsEmpty'\n | 'getIsRunning'\n | 'getItemExecutionCount'\n | 'getSize'\n > {\n /**\n * Signal version of `getAllItems`\n */\n allItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getBatchExecutionCount`\n */\n batchExecutionCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getItemExecutionCount`\n */\n itemExecutionCount: Accessor<number>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n}\n\n/**\n * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Batch processing of items using the provided `fn` function\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Example usage:\n * ```tsx\n * const batcher = createBatcher(\n * (items) => {\n * // Process batch of items\n * console.log('Processing batch:', items);\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batcher) => console.log('Batch executed'),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Add items to batch\n * batcher.addItem('task1');\n * batcher.addItem('task2');\n *\n * // Control the batcher\n * batcher.stop(); // Pause processing\n * batcher.start(); // Resume processing\n *\n * // Access batcher state via signals\n * console.log('Items:', batcher.allItems());\n * console.log('Size:', batcher.size());\n * console.log('Is empty:', batcher.isEmpty());\n * console.log('Is running:', batcher.isRunning());\n * console.log('Batch count:', batcher.batchExecutionCount());\n * console.log('Item count:', batcher.itemExecutionCount());\n * ```\n */\nexport function createBatcher<TValue>(\n fn: (items: Array<TValue>) => void,\n initialOptions: BatcherOptions<TValue> = {},\n): SolidBatcher<TValue> {\n const batcher = bindInstanceMethods(new Batcher<TValue>(fn, initialOptions))\n\n const [allItems, setAllItems] = createSignal<Array<TValue>>(\n batcher.getAllItems(),\n )\n const [batchExecutionCount, setBatchExecutionCount] = createSignal(\n batcher.getBatchExecutionCount(),\n )\n const [itemExecutionCount, setItemExecutionCount] = createSignal(\n batcher.getItemExecutionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(batcher.getIsEmpty())\n const [isRunning, setIsRunning] = createSignal(batcher.getIsRunning())\n const [size, setSize] = createSignal(batcher.getSize())\n\n function setOptions(newOptions: Partial<BatcherOptions<TValue>>) {\n batcher.setOptions({\n ...newOptions,\n onItemsChange: (batcher) => {\n setAllItems(batcher.getAllItems())\n setBatchExecutionCount(batcher.getBatchExecutionCount())\n setItemExecutionCount(batcher.getItemExecutionCount())\n setIsEmpty(batcher.getIsEmpty())\n setSize(batcher.getSize())\n\n const onItemsChange =\n newOptions.onItemsChange ?? initialOptions.onItemsChange\n onItemsChange?.(batcher)\n },\n onExecute: (batcher) => {\n setBatchExecutionCount(batcher.getBatchExecutionCount())\n setItemExecutionCount(batcher.getItemExecutionCount())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(batcher)\n },\n onIsRunningChange: (batcher) => {\n setIsRunning(batcher.getIsRunning())\n\n const onIsRunningChange =\n newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange\n onIsRunningChange?.(batcher)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...batcher,\n allItems,\n batchExecutionCount,\n isEmpty,\n isRunning,\n itemExecutionCount,\n size,\n setOptions,\n } as SolidBatcher<TValue>\n}\n"],"names":["batcher"],"mappings":";;;AAyFO,SAAS,cACd,IACA,iBAAyC,IACnB;AACtB,QAAM,UAAU,oBAAoB,IAAI,QAAgB,IAAI,cAAc,CAAC;AAErE,QAAA,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,QAAQ,YAAY;AAAA,EACtB;AACM,QAAA,CAAC,qBAAqB,sBAAsB,IAAI;AAAA,IACpD,QAAQ,uBAAuB;AAAA,EACjC;AACM,QAAA,CAAC,oBAAoB,qBAAqB,IAAI;AAAA,IAClD,QAAQ,sBAAsB;AAAA,EAChC;AACA,QAAM,CAAC,SAAS,UAAU,IAAI,aAAa,QAAQ,YAAY;AAC/D,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,QAAQ,cAAc;AACrE,QAAM,CAAC,MAAM,OAAO,IAAI,aAAa,QAAQ,SAAS;AAEtD,WAAS,WAAW,YAA6C;AAC/D,YAAQ,WAAW;AAAA,MACjB,GAAG;AAAA,MACH,eAAe,CAACA,aAAY;AACdA,oBAAAA,SAAQ,aAAa;AACVA,+BAAAA,SAAQ,wBAAwB;AACjCA,8BAAAA,SAAQ,uBAAuB;AAC1CA,mBAAAA,SAAQ,YAAY;AACvBA,gBAAAA,SAAQ,SAAS;AAEnB,cAAA,gBACJ,WAAW,iBAAiB,eAAe;AAC7C,uDAAgBA;AAAAA,MAClB;AAAA,MACA,WAAW,CAACA,aAAY;AACCA,+BAAAA,SAAQ,wBAAwB;AACjCA,8BAAAA,SAAQ,uBAAuB;AAE/C,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MACd;AAAA,MACA,mBAAmB,CAACA,aAAY;AACjBA,qBAAAA,SAAQ,cAAc;AAE7B,cAAA,oBACJ,WAAW,qBAAqB,eAAe;AACjD,+DAAoBA;AAAAA,MAAO;AAAA,IAC7B,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -0,0 +1,2 @@
1
+ export * from '@tanstack/pacer/batcher';
2
+ export * from './createBatcher.js';
@@ -0,0 +1,6 @@
1
+ export * from "@tanstack/pacer/batcher";
2
+ import { createBatcher } from "./createBatcher.js";
3
+ export {
4
+ createBatcher
5
+ };
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -6,6 +6,7 @@ export * from './async-debouncer/createAsyncDebouncer.js';
6
6
  export * from './async-queuer/createAsyncQueuer.js';
7
7
  export * from './async-rate-limiter/createAsyncRateLimiter.js';
8
8
  export * from './async-throttler/createAsyncThrottler.js';
9
+ export * from './batcher/createBatcher.js';
9
10
  export * from './debouncer/createDebouncedSignal.js';
10
11
  export * from './debouncer/createDebouncedValue.js';
11
12
  export * from './debouncer/createDebouncer.js';
package/dist/esm/index.js CHANGED
@@ -3,6 +3,7 @@ import { createAsyncDebouncer } from "./async-debouncer/createAsyncDebouncer.js"
3
3
  import { createAsyncQueuer } from "./async-queuer/createAsyncQueuer.js";
4
4
  import { createAsyncRateLimiter } from "./async-rate-limiter/createAsyncRateLimiter.js";
5
5
  import { createAsyncThrottler } from "./async-throttler/createAsyncThrottler.js";
6
+ import { createBatcher } from "./batcher/createBatcher.js";
6
7
  import { createDebouncedSignal } from "./debouncer/createDebouncedSignal.js";
7
8
  import { createDebouncedValue } from "./debouncer/createDebouncedValue.js";
8
9
  import { createDebouncer } from "./debouncer/createDebouncer.js";
@@ -18,6 +19,7 @@ export {
18
19
  createAsyncQueuer,
19
20
  createAsyncRateLimiter,
20
21
  createAsyncThrottler,
22
+ createBatcher,
21
23
  createDebouncedSignal,
22
24
  createDebouncedValue,
23
25
  createDebouncer,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
@@ -39,33 +39,39 @@ export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getAllItems'
39
39
  size: Accessor<number>;
40
40
  }
41
41
  /**
42
- * A Solid hook that creates and manages a Queuer instance.
42
+ * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.
43
43
  *
44
- * This is a lower-level hook that provides direct access to the Queuer's functionality without
45
- * any built-in state management. This allows you to integrate it with any state management solution
46
- * you prefer (createSignal, Redux, Zustand, etc.) by utilizing the onItemsChange callback.
44
+ * Features:
45
+ * - Synchronous processing of items using the provided `fn` function
46
+ * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
47
+ * - Priority queueing via `getPriority` or item `priority` property
48
+ * - Item expiration and removal of stale items
49
+ * - Configurable wait time between processing items
50
+ * - Pause/resume processing
51
+ * - Callbacks for queue state changes, execution, rejection, and expiration
52
+ * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
47
53
  *
48
- * For a hook with built-in state management, see createQueuerSignal.
54
+ * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.
49
55
  *
50
- * The Queuer extends the base Queue to add processing capabilities. Items are processed
51
- * synchronously in order, with optional delays between processing each item. The queuer includes
52
- * an internal tick mechanism that can be started and stopped, making it useful as a scheduler.
53
- * When started, it will process one item per tick, with an optional wait time between ticks.
56
+ * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.
54
57
  *
55
- * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO
56
- * (Last In First Out) by specifying 'front' position when adding items.
57
- *
58
- * @example
58
+ * Example usage:
59
59
  * ```tsx
60
- * // Example with custom state management and scheduling
60
+ * // Example with Solid signals and scheduling
61
61
  * const [items, setItems] = createSignal([]);
62
62
  *
63
- * const queue = createQueuer({
64
- * started: true, // Start processing immediately
65
- * wait: 1000, // Process one item every second
66
- * onItemsChange: (queue) => setItems(queue.getAllItems()),
67
- * getPriority: (item) => item.priority // Process higher priority items first
68
- * });
63
+ * const queue = createQueuer(
64
+ * (item) => {
65
+ * // process item synchronously
66
+ * console.log('Processing', item);
67
+ * },
68
+ * {
69
+ * started: true, // Start processing immediately
70
+ * wait: 1000, // Process one item every second
71
+ * onItemsChange: (queue) => setItems(queue.getAllItems()),
72
+ * getPriority: (item) => item.priority // Process higher priority items first
73
+ * }
74
+ * );
69
75
  *
70
76
  * // Add items to process - they'll be handled automatically
71
77
  * queue.addItem('task1');
@@ -83,4 +89,4 @@ export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getAllItems'
83
89
  * console.log('Next item:', queue.peek());
84
90
  * ```
85
91
  */
86
- export declare function createQueuer<TValue>(initialOptions?: QueuerOptions<TValue>): SolidQueuer<TValue>;
92
+ export declare function createQueuer<TValue>(fn: (item: TValue) => void, initialOptions?: QueuerOptions<TValue>): SolidQueuer<TValue>;
@@ -1,8 +1,8 @@
1
1
  import { Queuer } from "@tanstack/pacer/queuer";
2
2
  import { createSignal } from "solid-js";
3
3
  import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
- function createQueuer(initialOptions = {}) {
5
- const queuer = bindInstanceMethods(new Queuer(initialOptions));
4
+ function createQueuer(fn, initialOptions = {}) {
5
+ const queuer = bindInstanceMethods(new Queuer(fn, initialOptions));
6
6
  const [allItems, setAllItems] = createSignal(
7
7
  queuer.getAllItems()
8
8
  );
@@ -1 +1 @@
1
- {"version":3,"file":"createQueuer.js","sources":["../../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { QueuerOptions } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue>\n extends Omit<\n Queuer<TValue>,\n | 'getAllItems'\n | 'getExecutionCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getPeek'\n | 'getSize'\n > {\n /**\n * Signal version of `getAllItems`\n */\n allItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getExecutionCount`\n */\n executionCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsFull`\n */\n isFull: Accessor<boolean>\n /**\n * Signal version of `getIsIdle`\n */\n isIdle: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getPeek`\n */\n peek: Accessor<TValue | undefined>\n /**\n * Signal version of `getRejectionCount`\n */\n rejectionCount: Accessor<number>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n}\n\n/**\n * A Solid hook that creates and manages a Queuer instance.\n *\n * This is a lower-level hook that provides direct access to the Queuer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.) by utilizing the onItemsChange callback.\n *\n * For a hook with built-in state management, see createQueuerSignal.\n *\n * The Queuer extends the base Queue to add processing capabilities. Items are processed\n * synchronously in order, with optional delays between processing each item. The queuer includes\n * an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n * When started, it will process one item per tick, with an optional wait time between ticks.\n *\n * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO\n * (Last In First Out) by specifying 'front' position when adding items.\n *\n * @example\n * ```tsx\n * // Example with custom state management and scheduling\n * const [items, setItems] = createSignal([]);\n *\n * const queue = createQueuer({\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.getAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\n * });\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access queue state via signals\n * console.log('Items:', queue.allItems());\n * console.log('Size:', queue.size());\n * console.log('Is empty:', queue.isEmpty());\n * console.log('Is running:', queue.isRunning());\n * console.log('Next item:', queue.peek());\n * ```\n */\nexport function createQueuer<TValue>(\n initialOptions: QueuerOptions<TValue> = {},\n): SolidQueuer<TValue> {\n const queuer = bindInstanceMethods(new Queuer<TValue>(initialOptions))\n\n const [allItems, setAllItems] = createSignal<Array<TValue>>(\n queuer.getAllItems(),\n )\n const [executionCount, setExecutionCount] = createSignal(\n queuer.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n queuer.getRejectionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(queuer.getIsEmpty())\n const [isFull, setIsFull] = createSignal(queuer.getIsFull())\n const [isIdle, setIsIdle] = createSignal(queuer.getIsIdle())\n const [isRunning, setIsRunning] = createSignal(queuer.getIsRunning())\n const [peek, setPeek] = createSignal<TValue | undefined>(queuer.getPeek())\n const [size, setSize] = createSignal(queuer.getSize())\n\n function setOptions(newOptions: Partial<QueuerOptions<TValue>>) {\n queuer.setOptions({\n ...newOptions,\n onItemsChange: (queuer) => {\n setAllItems(queuer.getAllItems())\n setExecutionCount(queuer.getExecutionCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setPeek(() => queuer.getPeek())\n setSize(queuer.getSize())\n\n const onItemsChange =\n newOptions.onItemsChange ?? initialOptions.onItemsChange\n onItemsChange?.(queuer)\n },\n onIsRunningChange: (queuer) => {\n setIsRunning(queuer.getIsRunning())\n setIsIdle(queuer.getIsIdle())\n\n const onIsRunningChange =\n newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange\n onIsRunningChange?.(queuer)\n },\n onReject: (item, queuer) => {\n setRejectionCount(queuer.getRejectionCount())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(item, queuer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...queuer,\n allItems,\n executionCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n peek,\n rejectionCount,\n size,\n setOptions,\n } as SolidQueuer<TValue>\n}\n"],"names":["queuer"],"mappings":";;;AAqGgB,SAAA,aACd,iBAAwC,IACnB;AACrB,QAAM,SAAS,oBAAoB,IAAI,OAAe,cAAc,CAAC;AAE/D,QAAA,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,OAAO,YAAY;AAAA,EACrB;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,OAAO,kBAAkB;AAAA,EAC3B;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,OAAO,kBAAkB;AAAA,EAC3B;AACA,QAAM,CAAC,SAAS,UAAU,IAAI,aAAa,OAAO,YAAY;AAC9D,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,OAAO,WAAW;AAC3D,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,OAAO,WAAW;AAC3D,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,OAAO,cAAc;AACpE,QAAM,CAAC,MAAM,OAAO,IAAI,aAAiC,OAAO,SAAS;AACzE,QAAM,CAAC,MAAM,OAAO,IAAI,aAAa,OAAO,SAAS;AAErD,WAAS,WAAW,YAA4C;AAC9D,WAAO,WAAW;AAAA,MAChB,GAAG;AAAA,MACH,eAAe,CAACA,YAAW;AACbA,oBAAAA,QAAO,aAAa;AACdA,0BAAAA,QAAO,mBAAmB;AACjCA,mBAAAA,QAAO,YAAY;AACpBA,kBAAAA,QAAO,WAAW;AAClBA,kBAAAA,QAAO,WAAW;AACpB,gBAAA,MAAMA,QAAO,SAAS;AACtBA,gBAAAA,QAAO,SAAS;AAElB,cAAA,gBACJ,WAAW,iBAAiB,eAAe;AAC7C,uDAAgBA;AAAAA,MAClB;AAAA,MACA,mBAAmB,CAACA,YAAW;AAChBA,qBAAAA,QAAO,cAAc;AACxBA,kBAAAA,QAAO,WAAW;AAEtB,cAAA,oBACJ,WAAW,qBAAqB,eAAe;AACjD,+DAAoBA;AAAAA,MACtB;AAAA,MACA,UAAU,CAAC,MAAMA,YAAW;AACRA,0BAAAA,QAAO,mBAAmB;AAEtC,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAW,MAAMA;AAAAA,MAAM;AAAA,IACzB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"createQueuer.js","sources":["../../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { QueuerOptions } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue>\n extends Omit<\n Queuer<TValue>,\n | 'getAllItems'\n | 'getExecutionCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getPeek'\n | 'getSize'\n > {\n /**\n * Signal version of `getAllItems`\n */\n allItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getExecutionCount`\n */\n executionCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsFull`\n */\n isFull: Accessor<boolean>\n /**\n * Signal version of `getIsIdle`\n */\n isIdle: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getPeek`\n */\n peek: Accessor<TValue | undefined>\n /**\n * Signal version of `getRejectionCount`\n */\n rejectionCount: Accessor<number>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\n *\n * Example usage:\n * ```tsx\n * // Example with Solid signals and scheduling\n * const [items, setItems] = createSignal([]);\n *\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.getAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access queue state via signals\n * console.log('Items:', queue.allItems());\n * console.log('Size:', queue.size());\n * console.log('Is empty:', queue.isEmpty());\n * console.log('Is running:', queue.isRunning());\n * console.log('Next item:', queue.peek());\n * ```\n */\nexport function createQueuer<TValue>(\n fn: (item: TValue) => void,\n initialOptions: QueuerOptions<TValue> = {},\n): SolidQueuer<TValue> {\n const queuer = bindInstanceMethods(new Queuer<TValue>(fn, initialOptions))\n\n const [allItems, setAllItems] = createSignal<Array<TValue>>(\n queuer.getAllItems(),\n )\n const [executionCount, setExecutionCount] = createSignal(\n queuer.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n queuer.getRejectionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(queuer.getIsEmpty())\n const [isFull, setIsFull] = createSignal(queuer.getIsFull())\n const [isIdle, setIsIdle] = createSignal(queuer.getIsIdle())\n const [isRunning, setIsRunning] = createSignal(queuer.getIsRunning())\n const [peek, setPeek] = createSignal<TValue | undefined>(queuer.getPeek())\n const [size, setSize] = createSignal(queuer.getSize())\n\n function setOptions(newOptions: Partial<QueuerOptions<TValue>>) {\n queuer.setOptions({\n ...newOptions,\n onItemsChange: (queuer) => {\n setAllItems(queuer.getAllItems())\n setExecutionCount(queuer.getExecutionCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setPeek(() => queuer.getPeek())\n setSize(queuer.getSize())\n\n const onItemsChange =\n newOptions.onItemsChange ?? initialOptions.onItemsChange\n onItemsChange?.(queuer)\n },\n onIsRunningChange: (queuer) => {\n setIsRunning(queuer.getIsRunning())\n setIsIdle(queuer.getIsIdle())\n\n const onIsRunningChange =\n newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange\n onIsRunningChange?.(queuer)\n },\n onReject: (item, queuer) => {\n setRejectionCount(queuer.getRejectionCount())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(item, queuer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...queuer,\n allItems,\n executionCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n peek,\n rejectionCount,\n size,\n setOptions,\n } as SolidQueuer<TValue>\n}\n"],"names":["queuer"],"mappings":";;;AA2GO,SAAS,aACd,IACA,iBAAwC,IACnB;AACrB,QAAM,SAAS,oBAAoB,IAAI,OAAe,IAAI,cAAc,CAAC;AAEnE,QAAA,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,OAAO,YAAY;AAAA,EACrB;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,OAAO,kBAAkB;AAAA,EAC3B;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,OAAO,kBAAkB;AAAA,EAC3B;AACA,QAAM,CAAC,SAAS,UAAU,IAAI,aAAa,OAAO,YAAY;AAC9D,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,OAAO,WAAW;AAC3D,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,OAAO,WAAW;AAC3D,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,OAAO,cAAc;AACpE,QAAM,CAAC,MAAM,OAAO,IAAI,aAAiC,OAAO,SAAS;AACzE,QAAM,CAAC,MAAM,OAAO,IAAI,aAAa,OAAO,SAAS;AAErD,WAAS,WAAW,YAA4C;AAC9D,WAAO,WAAW;AAAA,MAChB,GAAG;AAAA,MACH,eAAe,CAACA,YAAW;AACbA,oBAAAA,QAAO,aAAa;AACdA,0BAAAA,QAAO,mBAAmB;AACjCA,mBAAAA,QAAO,YAAY;AACpBA,kBAAAA,QAAO,WAAW;AAClBA,kBAAAA,QAAO,WAAW;AACpB,gBAAA,MAAMA,QAAO,SAAS;AACtBA,gBAAAA,QAAO,SAAS;AAElB,cAAA,gBACJ,WAAW,iBAAiB,eAAe;AAC7C,uDAAgBA;AAAAA,MAClB;AAAA,MACA,mBAAmB,CAACA,YAAW;AAChBA,qBAAAA,QAAO,cAAc;AACxBA,kBAAAA,QAAO,WAAW;AAEtB,cAAA,oBACJ,WAAW,qBAAqB,eAAe;AACjD,+DAAoBA;AAAAA,MACtB;AAAA,MACA,UAAU,CAAC,MAAMA,YAAW;AACRA,0BAAAA,QAAO,mBAAmB;AAEtC,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAW,MAAMA;AAAAA,MAAM;AAAA,IACzB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-pacer",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Utilities for debouncing and throttling functions in Solid.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -77,6 +77,16 @@
77
77
  "default": "./dist/cjs/async-throttler/index.cjs"
78
78
  }
79
79
  },
80
+ "./batcher": {
81
+ "import": {
82
+ "types": "./dist/esm/batcher/index.d.ts",
83
+ "default": "./dist/esm/batcher/index.js"
84
+ },
85
+ "require": {
86
+ "types": "./dist/cjs/batcher/index.d.cts",
87
+ "default": "./dist/cjs/batcher/index.cjs"
88
+ }
89
+ },
80
90
  "./debouncer": {
81
91
  "import": {
82
92
  "types": "./dist/esm/debouncer/index.d.ts",
@@ -142,7 +152,7 @@
142
152
  "src"
143
153
  ],
144
154
  "dependencies": {
145
- "@tanstack/pacer": "0.6.0"
155
+ "@tanstack/pacer": "0.7.0"
146
156
  },
147
157
  "devDependencies": {
148
158
  "solid-js": "^1.9.6",
@@ -2,14 +2,11 @@ import { AsyncQueuer } from '@tanstack/pacer/async-queuer'
2
2
  import { createSignal } from 'solid-js'
3
3
  import { bindInstanceMethods } from '@tanstack/pacer/utils'
4
4
  import type { Accessor } from 'solid-js'
5
- import type {
6
- AsyncQueuerFn,
7
- AsyncQueuerOptions,
8
- } from '@tanstack/pacer/async-queuer'
5
+ import type { AsyncQueuerOptions } from '@tanstack/pacer/async-queuer'
9
6
 
10
- export interface SolidAsyncQueuer<TFn extends AsyncQueuerFn>
7
+ export interface SolidAsyncQueuer<TValue>
11
8
  extends Omit<
12
- AsyncQueuer<TFn>,
9
+ AsyncQueuer<TValue>,
13
10
  | 'getActiveItems'
14
11
  | 'getAllItems'
15
12
  | 'getErrorCount'
@@ -27,11 +24,11 @@ export interface SolidAsyncQueuer<TFn extends AsyncQueuerFn>
27
24
  /**
28
25
  * Signal version of `getActiveItems`
29
26
  */
30
- activeItems: Accessor<Array<TFn>>
27
+ activeItems: Accessor<Array<TValue>>
31
28
  /**
32
29
  * Signal version of `getAllItems`
33
30
  */
34
- allItems: Accessor<Array<TFn>>
31
+ allItems: Accessor<Array<TValue>>
35
32
  /**
36
33
  * Signal version of `getErrorCount`
37
34
  */
@@ -55,11 +52,11 @@ export interface SolidAsyncQueuer<TFn extends AsyncQueuerFn>
55
52
  /**
56
53
  * Signal version of `getPeek`
57
54
  */
58
- peek: Accessor<TFn | undefined>
55
+ peek: Accessor<TValue | undefined>
59
56
  /**
60
57
  * Signal version of `getPendingItems`
61
58
  */
62
- pendingItems: Accessor<Array<TFn>>
59
+ pendingItems: Accessor<Array<TValue>>
63
60
  /**
64
61
  * Signal version of `getRejectionCount`
65
62
  */
@@ -79,31 +76,35 @@ export interface SolidAsyncQueuer<TFn extends AsyncQueuerFn>
79
76
  }
80
77
 
81
78
  /**
82
- * A lower-level Solid hook that creates an `AsyncQueuer` instance for managing an async queue of items.
79
+ * Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.
83
80
  *
84
81
  * Features:
85
- * - Priority queue support via getPriority option
82
+ * - Priority queueing via `getPriority` or item `priority` property
86
83
  * - Configurable concurrency limit
87
- * - Task success/error/completion callbacks
88
84
  * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
89
- * - Pause/resume task processing
85
+ * - Pause/resume processing
90
86
  * - Task cancellation
91
- * - Item expiration to clear stale items from the queue
87
+ * - Item expiration
88
+ * - Lifecycle callbacks for success, error, settled, items change, etc.
89
+ * - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity
92
90
  *
93
91
  * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,
94
- * the next pending task is processed if below the concurrency limit.
92
+ * the next pending task is processed if the concurrency limit allows.
95
93
  *
96
94
  * Error Handling:
97
95
  * - If an `onError` handler is provided, it will be called with the error and queuer instance
98
96
  * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
99
97
  * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
100
- * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
98
+ * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
101
99
  * - The error state can be checked using the underlying AsyncQueuer instance
102
100
  *
103
- * @example
101
+ * Example usage:
104
102
  * ```tsx
105
103
  * // Basic async queuer for API requests
106
- * const asyncQueuer = createAsyncQueuer({
104
+ * const asyncQueuer = createAsyncQueuer(async (item) => {
105
+ * // process item
106
+ * return await fetchData(item);
107
+ * }, {
107
108
  * initialItems: [],
108
109
  * concurrency: 2,
109
110
  * maxSize: 100,
@@ -121,12 +122,16 @@ export interface SolidAsyncQueuer<TFn extends AsyncQueuerFn>
121
122
  *
122
123
  * // Start processing
123
124
  * asyncQueuer.start();
125
+ *
126
+ * // Use Solid signals in your UI
127
+ * const pending = asyncQueuer.pendingItems();
124
128
  * ```
125
129
  */
126
- export function createAsyncQueuer<TFn extends AsyncQueuerFn>(
127
- initialOptions: AsyncQueuerOptions<TFn> = {},
128
- ): SolidAsyncQueuer<TFn> {
129
- const asyncQueuer = new AsyncQueuer<TFn>(initialOptions)
130
+ export function createAsyncQueuer<TValue>(
131
+ fn: (value: TValue) => Promise<any>,
132
+ initialOptions: AsyncQueuerOptions<TValue> = {},
133
+ ): SolidAsyncQueuer<TValue> {
134
+ const asyncQueuer = new AsyncQueuer<TValue>(fn, initialOptions)
130
135
 
131
136
  const [successCount, setSuccessCount] = createSignal(
132
137
  asyncQueuer.getSuccessCount(),
@@ -142,16 +147,18 @@ export function createAsyncQueuer<TFn extends AsyncQueuerFn>(
142
147
  const [isFull, setIsFull] = createSignal(asyncQueuer.getIsFull())
143
148
  const [isIdle, setIsIdle] = createSignal(asyncQueuer.getIsIdle())
144
149
  const [isRunning, setIsRunning] = createSignal(asyncQueuer.getIsRunning())
145
- const [allItems, setAllItems] = createSignal<Array<TFn>>(
150
+ const [allItems, setAllItems] = createSignal<Array<TValue>>(
146
151
  asyncQueuer.getAllItems(),
147
152
  )
148
- const [activeItems, setActiveItems] = createSignal<Array<TFn>>(
153
+ const [activeItems, setActiveItems] = createSignal<Array<TValue>>(
149
154
  asyncQueuer.getActiveItems(),
150
155
  )
151
- const [pendingItems, setPendingItems] = createSignal<Array<TFn>>(
156
+ const [pendingItems, setPendingItems] = createSignal<Array<TValue>>(
152
157
  asyncQueuer.getPendingItems(),
153
158
  )
154
- const [peek, setPeek] = createSignal<TFn | undefined>(asyncQueuer.getPeek())
159
+ const [peek, setPeek] = createSignal<TValue | undefined>(
160
+ asyncQueuer.getPeek(),
161
+ )
155
162
  const [size, setSize] = createSignal(asyncQueuer.getSize())
156
163
 
157
164
  asyncQueuer.setOptions({
@@ -196,5 +203,5 @@ export function createAsyncQueuer<TFn extends AsyncQueuerFn>(
196
203
  settledCount,
197
204
  size,
198
205
  successCount,
199
- } as SolidAsyncQueuer<TFn>
206
+ } as SolidAsyncQueuer<TValue>
200
207
  }