@tanstack/solid-pacer 0.5.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.
- package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
- package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +21 -2
- package/dist/cjs/async-queuer/createAsyncQueuer.cjs +26 -13
- package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -1
- package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +47 -32
- package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
- package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +22 -7
- package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -1
- package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +15 -1
- 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 +2 -2
- package/dist/cjs/queuer/createQueuer.cjs.map +1 -1
- package/dist/cjs/queuer/createQueuer.d.cts +27 -21
- package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -1
- package/dist/cjs/rate-limiter/createRateLimiter.d.cts +4 -10
- package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +21 -2
- package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -1
- package/dist/esm/async-queuer/createAsyncQueuer.d.ts +47 -32
- package/dist/esm/async-queuer/createAsyncQueuer.js +26 -13
- package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -1
- package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +22 -7
- package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
- package/dist/esm/async-throttler/createAsyncThrottler.d.ts +15 -1
- package/dist/esm/async-throttler/createAsyncThrottler.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 +27 -21
- package/dist/esm/queuer/createQueuer.js +2 -2
- package/dist/esm/queuer/createQueuer.js.map +1 -1
- package/dist/esm/rate-limiter/createRateLimiter.d.ts +4 -10
- package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -1
- package/package.json +12 -2
- package/src/async-debouncer/createAsyncDebouncer.ts +21 -3
- package/src/async-queuer/createAsyncQueuer.ts +76 -48
- package/src/async-rate-limiter/createAsyncRateLimiter.ts +22 -7
- package/src/async-throttler/createAsyncThrottler.ts +15 -2
- 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 +28 -21
- package/src/rate-limiter/createRateLimiter.ts +4 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAsyncRateLimiter.js","sources":["../../../src/async-rate-limiter/createAsyncRateLimiter.ts"],"sourcesContent":["import { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { AsyncRateLimiterOptions } from '@tanstack/pacer/async-rate-limiter'\n\nexport interface SolidAsyncRateLimiter<TFn extends AnyAsyncFunction>\n extends Omit<\n AsyncRateLimiter<TFn>,\n | 'getSuccessCount'\n | 'getSettleCount'\n | 'getErrorCount'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n | 'getMsUntilNextWindow'\n > {\n successCount: Accessor<number>\n settleCount: Accessor<number>\n errorCount: Accessor<number>\n rejectionCount: Accessor<number>\n remainingInWindow: Accessor<number>\n msUntilNextWindow: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncRateLimiter` instance to limit how many times an async function can execute within a time window.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting allows
|
|
1
|
+
{"version":3,"file":"createAsyncRateLimiter.js","sources":["../../../src/async-rate-limiter/createAsyncRateLimiter.ts"],"sourcesContent":["import { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { AsyncRateLimiterOptions } from '@tanstack/pacer/async-rate-limiter'\n\nexport interface SolidAsyncRateLimiter<TFn extends AnyAsyncFunction>\n extends Omit<\n AsyncRateLimiter<TFn>,\n | 'getSuccessCount'\n | 'getSettleCount'\n | 'getErrorCount'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n | 'getMsUntilNextWindow'\n > {\n successCount: Accessor<number>\n settleCount: Accessor<number>\n errorCount: Accessor<number>\n rejectionCount: Accessor<number>\n remainingInWindow: Accessor<number>\n msUntilNextWindow: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncRateLimiter` instance to limit how many times an async function can execute within a time window.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple approach that allows a function to execute up to a limit within a time window,\n * then blocks all subsequent calls until the window passes. This can lead to \"bursty\" behavior where\n * all executions happen immediately, followed by a complete block.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * Unlike the non-async RateLimiter, this async version supports returning values from the rate-limited function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the rate-limited function.\n *\n * For smoother execution patterns, consider using:\n * - Throttling: Ensures consistent spacing between executions (e.g. max once per 200ms)\n * - Debouncing: Waits for a pause in calls before executing (e.g. after 500ms of no calls)\n *\n * Rate limiting is best used for hard API limits or resource constraints. For UI updates or\n * smoothing out frequent events, throttling or debouncing usually provide better user experience.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and rate limiter 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 AsyncRateLimiter instance\n * - Rate limit rejections (when limit is exceeded) are handled separately from execution errors via the `onReject` handler\n *\n * @example\n * ```tsx\n * // Basic API call rate limiting with return value\n * const { maybeExecute } = createAsyncRateLimiter(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data; // Return value is preserved\n * },\n * { limit: 5, window: 1000 } // 5 calls per second\n * );\n *\n * // With state management and return value\n * const [data, setData] = createSignal(null);\n * const { maybeExecute } = createAsyncRateLimiter(\n * async (query) => {\n * const result = await searchAPI(query);\n * setData(result);\n * return result; // Return value can be used by the caller\n * },\n * {\n * limit: 10,\n * window: 60000, // 10 calls per minute\n * onReject: (info) => console.log(`Rate limit exceeded: ${info.nextValidTime - Date.now()}ms until next window`)\n * }\n * );\n * ```\n */\nexport function createAsyncRateLimiter<TFn extends AnyAsyncFunction>(\n fn: TFn,\n initialOptions: AsyncRateLimiterOptions<TFn>,\n): SolidAsyncRateLimiter<TFn> {\n const asyncRateLimiter = new AsyncRateLimiter<TFn>(fn, initialOptions)\n\n const [successCount, setSuccessCount] = createSignal(\n asyncRateLimiter.getSuccessCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n asyncRateLimiter.getRejectionCount(),\n )\n const [errorCount, setErrorCount] = createSignal(\n asyncRateLimiter.getErrorCount(),\n )\n const [settleCount, setSettleCount] = createSignal(\n asyncRateLimiter.getSettleCount(),\n )\n const [remainingInWindow, setRemainingInWindow] = createSignal(\n asyncRateLimiter.getRemainingInWindow(),\n )\n const [msUntilNextWindow, setMsUntilNextWindow] = createSignal(\n asyncRateLimiter.getMsUntilNextWindow(),\n )\n\n function setOptions(newOptions: Partial<AsyncRateLimiterOptions<TFn>>) {\n asyncRateLimiter.setOptions({\n ...newOptions,\n onSettled: (rateLimiter) => {\n setSuccessCount(rateLimiter.getSuccessCount())\n setSettleCount(rateLimiter.getSettleCount())\n setErrorCount(rateLimiter.getErrorCount())\n setRejectionCount(rateLimiter.getRejectionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n\n const onSettled = newOptions.onSettled ?? initialOptions.onSettled\n onSettled?.(rateLimiter)\n },\n onReject: (rateLimiter) => {\n setRejectionCount(rateLimiter.getRejectionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(rateLimiter)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(asyncRateLimiter),\n errorCount,\n remainingInWindow,\n msUntilNextWindow,\n rejectionCount,\n setOptions,\n settleCount,\n successCount,\n } as SolidAsyncRateLimiter<TFn>\n}\n"],"names":[],"mappings":";;;AAuFgB,SAAA,uBACd,IACA,gBAC4B;AAC5B,QAAM,mBAAmB,IAAI,iBAAsB,IAAI,cAAc;AAE/D,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,iBAAiB,gBAAgB;AAAA,EACnC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,iBAAiB,kBAAkB;AAAA,EACrC;AACM,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC,iBAAiB,cAAc;AAAA,EACjC;AACM,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,iBAAiB,eAAe;AAAA,EAClC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,iBAAiB,qBAAqB;AAAA,EACxC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,iBAAiB,qBAAqB;AAAA,EACxC;AAEA,WAAS,WAAW,YAAmD;AACrE,qBAAiB,WAAW;AAAA,MAC1B,GAAG;AAAA,MACH,WAAW,CAAC,gBAAgB;AACV,wBAAA,YAAY,iBAAiB;AAC9B,uBAAA,YAAY,gBAAgB;AAC7B,sBAAA,YAAY,eAAe;AACvB,0BAAA,YAAY,mBAAmB;AAC5B,6BAAA,YAAY,sBAAsB;AAClC,6BAAA,YAAY,sBAAsB;AAEjD,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAY;AAAA,MACd;AAAA,MACA,UAAU,CAAC,gBAAgB;AACP,0BAAA,YAAY,mBAAmB;AAC5B,6BAAA,YAAY,sBAAsB;AAClC,6BAAA,YAAY,sBAAsB;AAEjD,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAW;AAAA,MAAW;AAAA,IACxB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG,oBAAoB,gBAAgB;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
|
|
@@ -21,6 +21,17 @@ export interface SolidAsyncThrottler<TFn extends AnyAsyncFunction> extends Omit<
|
|
|
21
21
|
* regardless of how many times it is called. This is useful for rate-limiting expensive API calls,
|
|
22
22
|
* database operations, or other async tasks.
|
|
23
23
|
*
|
|
24
|
+
* Unlike the non-async Throttler, this async version supports returning values from the throttled function,
|
|
25
|
+
* making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call
|
|
26
|
+
* instead of setting the result on a state variable from within the throttled function.
|
|
27
|
+
*
|
|
28
|
+
* Error Handling:
|
|
29
|
+
* - If an `onError` handler is provided, it will be called with the error and throttler instance
|
|
30
|
+
* - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
|
|
31
|
+
* - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
|
|
32
|
+
* - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
|
|
33
|
+
* - The error state can be checked using the underlying AsyncThrottler instance
|
|
34
|
+
*
|
|
24
35
|
* @example
|
|
25
36
|
* ```tsx
|
|
26
37
|
* // Basic API call throttling
|
|
@@ -42,7 +53,10 @@ export interface SolidAsyncThrottler<TFn extends AnyAsyncFunction> extends Omit<
|
|
|
42
53
|
* {
|
|
43
54
|
* wait: 2000,
|
|
44
55
|
* leading: true, // Execute immediately on first call
|
|
45
|
-
* trailing: false
|
|
56
|
+
* trailing: false, // Skip trailing edge updates
|
|
57
|
+
* onError: (error) => {
|
|
58
|
+
* console.error('API call failed:', error);
|
|
59
|
+
* }
|
|
46
60
|
* }
|
|
47
61
|
* );
|
|
48
62
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAsyncThrottler.js","sources":["../../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<TFn extends AnyAsyncFunction>\n extends Omit<\n AsyncThrottler<TFn>,\n | 'getSuccessCount'\n | 'getSettleCount'\n | 'getErrorCount'\n | 'getIsPending'\n | 'getIsExecuting'\n | 'getLastResult'\n | 'getLastExecutionTime'\n | 'getNextExecutionTime'\n > {\n successCount: Accessor<number>\n settleCount: Accessor<number>\n errorCount: Accessor<number>\n isPending: Accessor<boolean>\n isExecuting: Accessor<boolean>\n lastResult: Accessor<ReturnType<TFn> | undefined>\n lastExecutionTime: Accessor<number>\n nextExecutionTime: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async throttling ensures an async function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,\n * database operations, or other async tasks.\n *\n * @example\n * ```tsx\n * // Basic API call throttling\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // With state management\n * const [data, setData] = createSignal(null);\n * const { maybeExecute } = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * setData(result);\n * },\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false
|
|
1
|
+
{"version":3,"file":"createAsyncThrottler.js","sources":["../../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<TFn extends AnyAsyncFunction>\n extends Omit<\n AsyncThrottler<TFn>,\n | 'getSuccessCount'\n | 'getSettleCount'\n | 'getErrorCount'\n | 'getIsPending'\n | 'getIsExecuting'\n | 'getLastResult'\n | 'getLastExecutionTime'\n | 'getNextExecutionTime'\n > {\n successCount: Accessor<number>\n settleCount: Accessor<number>\n errorCount: Accessor<number>\n isPending: Accessor<boolean>\n isExecuting: Accessor<boolean>\n lastResult: Accessor<ReturnType<TFn> | undefined>\n lastExecutionTime: Accessor<number>\n nextExecutionTime: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async throttling ensures an async function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,\n * database operations, or other async tasks.\n *\n * Unlike the non-async Throttler, this async version supports returning values from the throttled function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the throttled function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and throttler 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 AsyncThrottler instance\n *\n * @example\n * ```tsx\n * // Basic API call throttling\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // With state management\n * const [data, setData] = createSignal(null);\n * const { maybeExecute } = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * setData(result);\n * },\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false, // Skip trailing edge updates\n * onError: (error) => {\n * console.error('API call failed:', error);\n * }\n * }\n * );\n * ```\n */\nexport function createAsyncThrottler<TFn extends AnyAsyncFunction>(\n fn: TFn,\n initialOptions: AsyncThrottlerOptions<TFn>,\n): SolidAsyncThrottler<TFn> {\n const asyncThrottler = bindInstanceMethods(\n new AsyncThrottler<TFn>(fn, initialOptions),\n )\n\n const [successCount, setSuccessCount] = createSignal(\n asyncThrottler.getSuccessCount(),\n )\n const [settleCount, setSettleCount] = createSignal(\n asyncThrottler.getSettleCount(),\n )\n const [errorCount, setErrorCount] = createSignal(\n asyncThrottler.getErrorCount(),\n )\n const [isPending, setIsPending] = createSignal(asyncThrottler.getIsPending())\n const [isExecuting, setIsExecuting] = createSignal(\n asyncThrottler.getIsExecuting(),\n )\n const [lastResult, setLastResult] = createSignal(\n asyncThrottler.getLastResult(),\n )\n const [lastExecutionTime, setLastExecutionTime] = createSignal(\n asyncThrottler.getLastExecutionTime(),\n )\n const [nextExecutionTime, setNextExecutionTime] = createSignal(\n asyncThrottler.getNextExecutionTime(),\n )\n\n function setOptions(newOptions: Partial<AsyncThrottlerOptions<TFn>>) {\n asyncThrottler.setOptions({\n ...newOptions,\n onSettled: (throttler) => {\n setSuccessCount(throttler.getSuccessCount())\n setSettleCount(throttler.getSettleCount())\n setErrorCount(throttler.getErrorCount())\n setIsPending(throttler.getIsPending())\n setIsExecuting(throttler.getIsExecuting())\n setLastExecutionTime(throttler.getLastExecutionTime())\n setNextExecutionTime(throttler.getNextExecutionTime())\n setLastResult(throttler.getLastResult())\n\n const onSettled = newOptions.onSettled ?? initialOptions.onSettled\n onSettled?.(throttler)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...asyncThrottler,\n errorCount,\n isExecuting,\n isPending,\n lastExecutionTime,\n lastResult,\n nextExecutionTime,\n setOptions,\n settleCount,\n successCount,\n } as SolidAsyncThrottler<TFn>\n}\n"],"names":[],"mappings":";;;AA+EgB,SAAA,qBACd,IACA,gBAC0B;AAC1B,QAAM,iBAAiB;AAAA,IACrB,IAAI,eAAoB,IAAI,cAAc;AAAA,EAC5C;AAEM,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,eAAe,gBAAgB;AAAA,EACjC;AACM,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,eAAe,eAAe;AAAA,EAChC;AACM,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC,eAAe,cAAc;AAAA,EAC/B;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,eAAe,cAAc;AACtE,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,eAAe,eAAe;AAAA,EAChC;AACM,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC,eAAe,cAAc;AAAA,EAC/B;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,eAAe,qBAAqB;AAAA,EACtC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,eAAe,qBAAqB;AAAA,EACtC;AAEA,WAAS,WAAW,YAAiD;AACnE,mBAAe,WAAW;AAAA,MACxB,GAAG;AAAA,MACH,WAAW,CAAC,cAAc;AACR,wBAAA,UAAU,iBAAiB;AAC5B,uBAAA,UAAU,gBAAgB;AAC3B,sBAAA,UAAU,eAAe;AAC1B,qBAAA,UAAU,cAAc;AACtB,uBAAA,UAAU,gBAAgB;AACpB,6BAAA,UAAU,sBAAsB;AAChC,6BAAA,UAAU,sBAAsB;AACvC,sBAAA,UAAU,eAAe;AAEjC,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAY;AAAA,MAAS;AAAA,IACvB,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,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 @@
|
|
|
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":";;;;;;;;;;;;;;;;"}
|
|
@@ -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.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 *
|
|
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;"}
|
|
@@ -34,17 +34,11 @@ export interface SolidRateLimiter<TFn extends AnyFunction> extends Omit<RateLimi
|
|
|
34
34
|
* const rateLimiter = createRateLimiter(apiCall, {
|
|
35
35
|
* limit: 5,
|
|
36
36
|
* window: 60000,
|
|
37
|
-
* windowType: 'sliding'
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* // Monitor rate limit status
|
|
41
|
-
* const handleClick = () => {
|
|
42
|
-
* if (rateLimiter.remainingInWindow() > 0) {
|
|
43
|
-
* rateLimiter.maybeExecute(data);
|
|
44
|
-
* } else {
|
|
45
|
-
* showRateLimitWarning();
|
|
37
|
+
* windowType: 'sliding',
|
|
38
|
+
* onReject: (rateLimiter) => {
|
|
39
|
+
* console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
|
|
46
40
|
* }
|
|
47
|
-
* };
|
|
41
|
+
* });
|
|
48
42
|
*
|
|
49
43
|
* // Access rate limiter state via signals
|
|
50
44
|
* console.log('Executions:', rateLimiter.executionCount());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRateLimiter.js","sources":["../../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<TFn extends AnyFunction>\n extends Omit<\n RateLimiter<TFn>,\n | 'getExecutionCount'\n | 'getMsUntilNextWindow'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n > {\n executionCount: Accessor<number>\n msUntilNextWindow: Accessor<number>\n rejectionCount: Accessor<number>\n remainingInWindow: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * @example\n * ```tsx\n * // Basic rate limiting - max 5 calls per minute with a sliding window\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'
|
|
1
|
+
{"version":3,"file":"createRateLimiter.js","sources":["../../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<TFn extends AnyFunction>\n extends Omit<\n RateLimiter<TFn>,\n | 'getExecutionCount'\n | 'getMsUntilNextWindow'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n > {\n executionCount: Accessor<number>\n msUntilNextWindow: Accessor<number>\n rejectionCount: Accessor<number>\n remainingInWindow: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * @example\n * ```tsx\n * // Basic rate limiting - max 5 calls per minute with a sliding window\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * onReject: (rateLimiter) => {\n * console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rate limiter state via signals\n * console.log('Executions:', rateLimiter.executionCount());\n * console.log('Rejections:', rateLimiter.rejectionCount());\n * console.log('Remaining:', rateLimiter.remainingInWindow());\n * console.log('Next window in:', rateLimiter.msUntilNextWindow());\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction>(\n fn: TFn,\n initialOptions: RateLimiterOptions<TFn>,\n): SolidRateLimiter<TFn> {\n const rateLimiter = bindInstanceMethods(\n new RateLimiter<TFn>(fn, initialOptions),\n )\n\n const [executionCount, setExecutionCount] = createSignal(\n rateLimiter.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n rateLimiter.getRejectionCount(),\n )\n const [remainingInWindow, setRemainingInWindow] = createSignal(\n rateLimiter.getRemainingInWindow(),\n )\n const [msUntilNextWindow, setMsUntilNextWindow] = createSignal(\n rateLimiter.getMsUntilNextWindow(),\n )\n\n function setOptions(newOptions: Partial<RateLimiterOptions<TFn>>) {\n rateLimiter.setOptions({\n ...newOptions,\n onExecute: (rateLimiter) => {\n setExecutionCount(rateLimiter.getExecutionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(rateLimiter)\n },\n onReject: (rateLimiter) => {\n setRejectionCount(rateLimiter.getRejectionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(rateLimiter)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...rateLimiter,\n executionCount,\n rejectionCount,\n remainingInWindow,\n msUntilNextWindow,\n setOptions,\n } as SolidRateLimiter<TFn>\n}\n"],"names":["rateLimiter"],"mappings":";;;AA6DgB,SAAA,kBACd,IACA,gBACuB;AACvB,QAAM,cAAc;AAAA,IAClB,IAAI,YAAiB,IAAI,cAAc;AAAA,EACzC;AAEM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,YAAY,qBAAqB;AAAA,EACnC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,YAAY,qBAAqB;AAAA,EACnC;AAEA,WAAS,WAAW,YAA8C;AAChE,gBAAY,WAAW;AAAA,MACrB,GAAG;AAAA,MACH,WAAW,CAACA,iBAAgB;AACRA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AAEjD,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MACd;AAAA,MACA,UAAU,CAACA,iBAAgB;AACPA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AAEjD,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAWA;AAAAA,MAAW;AAAA,IACxB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG;AAAA,IACH;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.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.
|
|
155
|
+
"@tanstack/pacer": "0.7.0"
|
|
146
156
|
},
|
|
147
157
|
"devDependencies": {
|
|
148
158
|
"solid-js": "^1.9.6",
|
|
@@ -28,8 +28,22 @@ export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction>
|
|
|
28
28
|
* you can integrate with any state management solution (createSignal, etc).
|
|
29
29
|
*
|
|
30
30
|
* Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* Each new invocation resets the delay timer. This is useful for handling frequent events like window resizing
|
|
32
|
+
* or input changes where you only want to execute the handler after the events have stopped occurring.
|
|
33
|
+
*
|
|
34
|
+
* Unlike throttling which allows execution at regular intervals, debouncing prevents any execution until
|
|
35
|
+
* the function stops being called for the specified delay period.
|
|
36
|
+
*
|
|
37
|
+
* Unlike the non-async Debouncer, this async version supports returning values from the debounced function,
|
|
38
|
+
* making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call
|
|
39
|
+
* instead of setting the result on a state variable from within the debounced function.
|
|
40
|
+
*
|
|
41
|
+
* Error Handling:
|
|
42
|
+
* - If an `onError` handler is provided, it will be called with the error and debouncer instance
|
|
43
|
+
* - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
|
|
44
|
+
* - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
|
|
45
|
+
* - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
|
|
46
|
+
* - The error state can be checked using the underlying AsyncDebouncer instance
|
|
33
47
|
*
|
|
34
48
|
* @example
|
|
35
49
|
* ```tsx
|
|
@@ -51,11 +65,15 @@ export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction>
|
|
|
51
65
|
* },
|
|
52
66
|
* {
|
|
53
67
|
* wait: 300,
|
|
68
|
+
* leading: true, // Execute immediately on first call
|
|
69
|
+
* trailing: false, // Skip trailing edge updates
|
|
70
|
+
* onError: (error) => {
|
|
71
|
+
* console.error('API call failed:', error);
|
|
72
|
+
* }
|
|
54
73
|
* }
|
|
55
74
|
* );
|
|
56
75
|
* ```
|
|
57
76
|
*/
|
|
58
|
-
|
|
59
77
|
export function createAsyncDebouncer<TFn extends AnyAsyncFunction>(
|
|
60
78
|
fn: TFn,
|
|
61
79
|
initialOptions: AsyncDebouncerOptions<TFn>,
|