@tanstack/solid-pacer 0.6.0 → 0.8.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.
- package/dist/cjs/async-queuer/createAsyncQueuer.cjs +13 -11
- package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -1
- package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +27 -20
- package/dist/cjs/batcher/createBatcher.cjs +58 -0
- package/dist/cjs/batcher/createBatcher.cjs.map +1 -0
- package/dist/cjs/batcher/createBatcher.d.cts +76 -0
- package/dist/cjs/batcher/index.cjs +12 -0
- package/dist/cjs/batcher/index.cjs.map +1 -0
- package/dist/cjs/batcher/index.d.cts +2 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -0
- package/dist/cjs/queuer/createQueuer.cjs +9 -7
- package/dist/cjs/queuer/createQueuer.cjs.map +1 -1
- package/dist/cjs/queuer/createQueuer.d.cts +32 -26
- package/dist/esm/async-queuer/createAsyncQueuer.d.ts +27 -20
- package/dist/esm/async-queuer/createAsyncQueuer.js +13 -11
- package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -1
- package/dist/esm/batcher/createBatcher.d.ts +76 -0
- package/dist/esm/batcher/createBatcher.js +58 -0
- package/dist/esm/batcher/createBatcher.js.map +1 -0
- package/dist/esm/batcher/index.d.ts +2 -0
- package/dist/esm/batcher/index.js +6 -0
- package/dist/esm/batcher/index.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/queuer/createQueuer.d.ts +32 -26
- package/dist/esm/queuer/createQueuer.js +9 -7
- package/dist/esm/queuer/createQueuer.js.map +1 -1
- package/package.json +13 -3
- package/src/async-queuer/createAsyncQueuer.ts +51 -44
- package/src/batcher/createBatcher.ts +152 -0
- package/src/batcher/index.ts +3 -0
- package/src/index.ts +3 -0
- package/src/queuer/createQueuer.ts +41 -32
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { AsyncQueuer,
|
|
1
|
+
import { AsyncQueuer, AsyncQueuerOptions } from '@tanstack/pacer/async-queuer';
|
|
2
2
|
import { Accessor } from 'solid-js';
|
|
3
|
-
export interface SolidAsyncQueuer<
|
|
3
|
+
export interface SolidAsyncQueuer<TValue> extends Omit<AsyncQueuer<TValue>, 'getErrorCount' | 'getIsEmpty' | 'getIsFull' | 'getIsIdle' | 'getIsRunning' | 'getRejectionCount' | 'getSettledCount' | 'getSize' | 'getSuccessCount' | 'peekActiveItems' | 'peekAllItems' | 'peekNextItem' | 'peekPendingItems'> {
|
|
4
4
|
/**
|
|
5
|
-
* Signal version of `
|
|
5
|
+
* Signal version of `peekActiveItems`
|
|
6
6
|
*/
|
|
7
|
-
activeItems: Accessor<Array<
|
|
7
|
+
activeItems: Accessor<Array<TValue>>;
|
|
8
8
|
/**
|
|
9
|
-
* Signal version of `
|
|
9
|
+
* Signal version of `peekAllItems`
|
|
10
10
|
*/
|
|
11
|
-
allItems: Accessor<Array<
|
|
11
|
+
allItems: Accessor<Array<TValue>>;
|
|
12
12
|
/**
|
|
13
13
|
* Signal version of `getErrorCount`
|
|
14
14
|
*/
|
|
@@ -30,13 +30,13 @@ export interface SolidAsyncQueuer<TFn extends AsyncQueuerFn> extends Omit<AsyncQ
|
|
|
30
30
|
*/
|
|
31
31
|
isRunning: Accessor<boolean>;
|
|
32
32
|
/**
|
|
33
|
-
* Signal version of `
|
|
33
|
+
* Signal version of `peekNextItem`
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
nextItem: Accessor<TValue | undefined>;
|
|
36
36
|
/**
|
|
37
|
-
* Signal version of `
|
|
37
|
+
* Signal version of `peekPendingItems`
|
|
38
38
|
*/
|
|
39
|
-
pendingItems: Accessor<Array<
|
|
39
|
+
pendingItems: Accessor<Array<TValue>>;
|
|
40
40
|
/**
|
|
41
41
|
* Signal version of `getRejectionCount`
|
|
42
42
|
*/
|
|
@@ -55,31 +55,35 @@ export interface SolidAsyncQueuer<TFn extends AsyncQueuerFn> extends Omit<AsyncQ
|
|
|
55
55
|
successCount: Accessor<number>;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.
|
|
59
59
|
*
|
|
60
60
|
* Features:
|
|
61
|
-
* - Priority
|
|
61
|
+
* - Priority queueing via `getPriority` or item `priority` property
|
|
62
62
|
* - Configurable concurrency limit
|
|
63
|
-
* - Task success/error/completion callbacks
|
|
64
63
|
* - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
|
|
65
|
-
* - Pause/resume
|
|
64
|
+
* - Pause/resume processing
|
|
66
65
|
* - Task cancellation
|
|
67
|
-
* - Item expiration
|
|
66
|
+
* - Item expiration
|
|
67
|
+
* - Lifecycle callbacks for success, error, settled, items change, etc.
|
|
68
|
+
* - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity
|
|
68
69
|
*
|
|
69
70
|
* Tasks are processed concurrently up to the configured concurrency limit. When a task completes,
|
|
70
|
-
* the next pending task is processed if
|
|
71
|
+
* the next pending task is processed if the concurrency limit allows.
|
|
71
72
|
*
|
|
72
73
|
* Error Handling:
|
|
73
74
|
* - If an `onError` handler is provided, it will be called with the error and queuer instance
|
|
74
75
|
* - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
|
|
75
76
|
* - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
|
|
76
|
-
* - Both onError and throwOnError can be used together
|
|
77
|
+
* - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
|
|
77
78
|
* - The error state can be checked using the underlying AsyncQueuer instance
|
|
78
79
|
*
|
|
79
|
-
*
|
|
80
|
+
* Example usage:
|
|
80
81
|
* ```tsx
|
|
81
82
|
* // Basic async queuer for API requests
|
|
82
|
-
* const asyncQueuer = createAsyncQueuer({
|
|
83
|
+
* const asyncQueuer = createAsyncQueuer(async (item) => {
|
|
84
|
+
* // process item
|
|
85
|
+
* return await fetchData(item);
|
|
86
|
+
* }, {
|
|
83
87
|
* initialItems: [],
|
|
84
88
|
* concurrency: 2,
|
|
85
89
|
* maxSize: 100,
|
|
@@ -97,6 +101,9 @@ export interface SolidAsyncQueuer<TFn extends AsyncQueuerFn> extends Omit<AsyncQ
|
|
|
97
101
|
*
|
|
98
102
|
* // Start processing
|
|
99
103
|
* asyncQueuer.start();
|
|
104
|
+
*
|
|
105
|
+
* // Use Solid signals in your UI
|
|
106
|
+
* const pending = asyncQueuer.pendingItems();
|
|
100
107
|
* ```
|
|
101
108
|
*/
|
|
102
|
-
export declare function createAsyncQueuer<
|
|
109
|
+
export declare function createAsyncQueuer<TValue>(fn: (value: TValue) => Promise<any>, initialOptions?: AsyncQueuerOptions<TValue>): SolidAsyncQueuer<TValue>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AsyncQueuer } from "@tanstack/pacer/async-queuer";
|
|
2
2
|
import { createSignal } from "solid-js";
|
|
3
3
|
import { bindInstanceMethods } from "@tanstack/pacer/utils";
|
|
4
|
-
function createAsyncQueuer(initialOptions = {}) {
|
|
5
|
-
const asyncQueuer = new AsyncQueuer(initialOptions);
|
|
4
|
+
function createAsyncQueuer(fn, initialOptions = {}) {
|
|
5
|
+
const asyncQueuer = new AsyncQueuer(fn, initialOptions);
|
|
6
6
|
const [successCount, setSuccessCount] = createSignal(
|
|
7
7
|
asyncQueuer.getSuccessCount()
|
|
8
8
|
);
|
|
@@ -18,27 +18,29 @@ function createAsyncQueuer(initialOptions = {}) {
|
|
|
18
18
|
const [isIdle, setIsIdle] = createSignal(asyncQueuer.getIsIdle());
|
|
19
19
|
const [isRunning, setIsRunning] = createSignal(asyncQueuer.getIsRunning());
|
|
20
20
|
const [allItems, setAllItems] = createSignal(
|
|
21
|
-
asyncQueuer.
|
|
21
|
+
asyncQueuer.peekAllItems()
|
|
22
22
|
);
|
|
23
23
|
const [activeItems, setActiveItems] = createSignal(
|
|
24
|
-
asyncQueuer.
|
|
24
|
+
asyncQueuer.peekActiveItems()
|
|
25
25
|
);
|
|
26
26
|
const [pendingItems, setPendingItems] = createSignal(
|
|
27
|
-
asyncQueuer.
|
|
27
|
+
asyncQueuer.peekPendingItems()
|
|
28
|
+
);
|
|
29
|
+
const [nextItem, setNextItem] = createSignal(
|
|
30
|
+
asyncQueuer.peekNextItem()
|
|
28
31
|
);
|
|
29
|
-
const [peek, setPeek] = createSignal(asyncQueuer.getPeek());
|
|
30
32
|
const [size, setSize] = createSignal(asyncQueuer.getSize());
|
|
31
33
|
asyncQueuer.setOptions({
|
|
32
34
|
onItemsChange: (queuer) => {
|
|
33
35
|
var _a;
|
|
34
|
-
setActiveItems(queuer.
|
|
35
|
-
setAllItems(queuer.
|
|
36
|
+
setActiveItems(queuer.peekActiveItems());
|
|
37
|
+
setAllItems(queuer.peekAllItems());
|
|
36
38
|
setErrorCount(queuer.getErrorCount());
|
|
37
39
|
setIsEmpty(queuer.getIsEmpty());
|
|
38
40
|
setIsFull(queuer.getIsFull());
|
|
39
41
|
setIsIdle(queuer.getIsIdle());
|
|
40
|
-
|
|
41
|
-
setPendingItems(queuer.
|
|
42
|
+
setNextItem(() => queuer.peekNextItem());
|
|
43
|
+
setPendingItems(queuer.peekPendingItems());
|
|
42
44
|
setRejectionCount(queuer.getRejectionCount());
|
|
43
45
|
setSettledCount(queuer.getSettledCount());
|
|
44
46
|
setSize(queuer.getSize());
|
|
@@ -66,7 +68,7 @@ function createAsyncQueuer(initialOptions = {}) {
|
|
|
66
68
|
isFull,
|
|
67
69
|
isIdle,
|
|
68
70
|
isRunning,
|
|
69
|
-
|
|
71
|
+
nextItem,
|
|
70
72
|
pendingItems,
|
|
71
73
|
rejectionCount,
|
|
72
74
|
settledCount,
|
|
@@ -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 {
|
|
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 | 'getErrorCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getRejectionCount'\n | 'getSettledCount'\n | 'getSize'\n | 'getSuccessCount'\n | 'peekActiveItems'\n | 'peekAllItems'\n | 'peekNextItem'\n | 'peekPendingItems'\n > {\n /**\n * Signal version of `peekActiveItems`\n */\n activeItems: Accessor<Array<TValue>>\n /**\n * Signal version of `peekAllItems`\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 `peekNextItem`\n */\n nextItem: Accessor<TValue | undefined>\n /**\n * Signal version of `peekPendingItems`\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.peekAllItems(),\n )\n const [activeItems, setActiveItems] = createSignal<Array<TValue>>(\n asyncQueuer.peekActiveItems(),\n )\n const [pendingItems, setPendingItems] = createSignal<Array<TValue>>(\n asyncQueuer.peekPendingItems(),\n )\n const [nextItem, setNextItem] = createSignal<TValue | undefined>(\n asyncQueuer.peekNextItem(),\n )\n const [size, setSize] = createSignal(asyncQueuer.getSize())\n\n asyncQueuer.setOptions({\n onItemsChange: (queuer) => {\n setActiveItems(queuer.peekActiveItems())\n setAllItems(queuer.peekAllItems())\n setErrorCount(queuer.getErrorCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setNextItem(() => queuer.peekNextItem())\n setPendingItems(queuer.peekPendingItems())\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 nextItem,\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,aAAa;AAAA,EAC3B;AACM,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,YAAY,gBAAgB;AAAA,EAC9B;AACM,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,YAAY,iBAAiB;AAAA,EAC/B;AACM,QAAA,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,YAAY,aAAa;AAAA,EAC3B;AACA,QAAM,CAAC,MAAM,OAAO,IAAI,aAAa,YAAY,SAAS;AAE1D,cAAY,WAAW;AAAA,IACrB,eAAe,CAAC,WAAW;;AACV,qBAAA,OAAO,iBAAiB;AAC3B,kBAAA,OAAO,cAAc;AACnB,oBAAA,OAAO,eAAe;AACzB,iBAAA,OAAO,YAAY;AACpB,gBAAA,OAAO,WAAW;AAClB,gBAAA,OAAO,WAAW;AAChB,kBAAA,MAAM,OAAO,cAAc;AACvB,sBAAA,OAAO,kBAAkB;AACvB,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>, 'peekAllItems' | 'getBatchExecutionCount' | 'getIsEmpty' | 'getIsRunning' | 'getItemExecutionCount' | 'getSize'> {
|
|
4
|
+
/**
|
|
5
|
+
* Signal version of `peekAllItems`
|
|
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.peekAllItems()
|
|
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.peekAllItems());
|
|
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 | 'peekAllItems'\n | 'getBatchExecutionCount'\n | 'getIsEmpty'\n | 'getIsRunning'\n | 'getItemExecutionCount'\n | 'getSize'\n > {\n /**\n * Signal version of `peekAllItems`\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.peekAllItems(),\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.peekAllItems())\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,aAAa;AAAA,EACvB;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,cAAc;AACXA,+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 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -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,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Queuer, QueuerOptions } from '@tanstack/pacer/queuer';
|
|
2
2
|
import { Accessor } from 'solid-js';
|
|
3
|
-
export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, '
|
|
3
|
+
export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getExecutionCount' | 'getIsEmpty' | 'getIsFull' | 'getIsIdle' | 'getIsRunning' | 'getSize' | 'peekAllItems' | 'peekNextItem'> {
|
|
4
4
|
/**
|
|
5
|
-
* Signal version of `
|
|
5
|
+
* Signal version of `peekAllItems`
|
|
6
6
|
*/
|
|
7
7
|
allItems: Accessor<Array<TValue>>;
|
|
8
8
|
/**
|
|
@@ -26,9 +26,9 @@ export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getAllItems'
|
|
|
26
26
|
*/
|
|
27
27
|
isRunning: Accessor<boolean>;
|
|
28
28
|
/**
|
|
29
|
-
* Signal version of `
|
|
29
|
+
* Signal version of `peekNextItem`
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
nextItem: Accessor<TValue | undefined>;
|
|
32
32
|
/**
|
|
33
33
|
* Signal version of `getRejectionCount`
|
|
34
34
|
*/
|
|
@@ -39,33 +39,39 @@ export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getAllItems'
|
|
|
39
39
|
size: Accessor<number>;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.
|
|
43
43
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
56
|
-
* (Last In First Out) by specifying 'front' position when adding items.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
58
|
+
* Example usage:
|
|
59
59
|
* ```tsx
|
|
60
|
-
* // Example with
|
|
60
|
+
* // Example with Solid signals and scheduling
|
|
61
61
|
* const [items, setItems] = createSignal([]);
|
|
62
62
|
*
|
|
63
|
-
* const queue = createQueuer(
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
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.peekAllItems()),
|
|
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');
|
|
@@ -80,7 +86,7 @@ export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getAllItems'
|
|
|
80
86
|
* console.log('Size:', queue.size());
|
|
81
87
|
* console.log('Is empty:', queue.isEmpty());
|
|
82
88
|
* console.log('Is running:', queue.isRunning());
|
|
83
|
-
* console.log('Next item:', queue.
|
|
89
|
+
* console.log('Next item:', queue.nextItem());
|
|
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,10 +1,10 @@
|
|
|
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
|
-
queuer.
|
|
7
|
+
queuer.peekAllItems()
|
|
8
8
|
);
|
|
9
9
|
const [executionCount, setExecutionCount] = createSignal(
|
|
10
10
|
queuer.getExecutionCount()
|
|
@@ -16,18 +16,20 @@ function createQueuer(initialOptions = {}) {
|
|
|
16
16
|
const [isFull, setIsFull] = createSignal(queuer.getIsFull());
|
|
17
17
|
const [isIdle, setIsIdle] = createSignal(queuer.getIsIdle());
|
|
18
18
|
const [isRunning, setIsRunning] = createSignal(queuer.getIsRunning());
|
|
19
|
-
const [
|
|
19
|
+
const [nextItem, setNextItem] = createSignal(
|
|
20
|
+
queuer.peekNextItem()
|
|
21
|
+
);
|
|
20
22
|
const [size, setSize] = createSignal(queuer.getSize());
|
|
21
23
|
function setOptions(newOptions) {
|
|
22
24
|
queuer.setOptions({
|
|
23
25
|
...newOptions,
|
|
24
26
|
onItemsChange: (queuer2) => {
|
|
25
|
-
setAllItems(queuer2.
|
|
27
|
+
setAllItems(queuer2.peekAllItems());
|
|
26
28
|
setExecutionCount(queuer2.getExecutionCount());
|
|
27
29
|
setIsEmpty(queuer2.getIsEmpty());
|
|
28
30
|
setIsFull(queuer2.getIsFull());
|
|
29
31
|
setIsIdle(queuer2.getIsIdle());
|
|
30
|
-
|
|
32
|
+
setNextItem(() => queuer2.peekNextItem());
|
|
31
33
|
setSize(queuer2.getSize());
|
|
32
34
|
const onItemsChange = newOptions.onItemsChange ?? initialOptions.onItemsChange;
|
|
33
35
|
onItemsChange == null ? void 0 : onItemsChange(queuer2);
|
|
@@ -54,7 +56,7 @@ function createQueuer(initialOptions = {}) {
|
|
|
54
56
|
isFull,
|
|
55
57
|
isIdle,
|
|
56
58
|
isRunning,
|
|
57
|
-
|
|
59
|
+
nextItem,
|
|
58
60
|
rejectionCount,
|
|
59
61
|
size,
|
|
60
62
|
setOptions
|
|
@@ -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 | '
|
|
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 | 'getExecutionCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getSize'\n | 'peekAllItems'\n | 'peekNextItem'\n > {\n /**\n * Signal version of `peekAllItems`\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 `peekNextItem`\n */\n nextItem: 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.peekAllItems()),\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.nextItem());\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.peekAllItems(),\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 [nextItem, setNextItem] = createSignal<TValue | undefined>(\n queuer.peekNextItem(),\n )\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.peekAllItems())\n setExecutionCount(queuer.getExecutionCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setNextItem(() => queuer.peekNextItem())\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 nextItem,\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,aAAa;AAAA,EACtB;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;AAC9D,QAAA,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,OAAO,aAAa;AAAA,EACtB;AACA,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,cAAc;AACfA,0BAAAA,QAAO,mBAAmB;AACjCA,mBAAAA,QAAO,YAAY;AACpBA,kBAAAA,QAAO,WAAW;AAClBA,kBAAAA,QAAO,WAAW;AAChB,oBAAA,MAAMA,QAAO,cAAc;AAC/BA,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.
|
|
3
|
+
"version": "0.8.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,10 +152,10 @@
|
|
|
142
152
|
"src"
|
|
143
153
|
],
|
|
144
154
|
"dependencies": {
|
|
145
|
-
"@tanstack/pacer": "0.
|
|
155
|
+
"@tanstack/pacer": "0.8.0"
|
|
146
156
|
},
|
|
147
157
|
"devDependencies": {
|
|
148
|
-
"solid-js": "^1.9.
|
|
158
|
+
"solid-js": "^1.9.7",
|
|
149
159
|
"vite-plugin-solid": "^2.11.6"
|
|
150
160
|
},
|
|
151
161
|
"peerDependencies": {
|