@tanstack/pacer 0.11.0 → 0.13.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-batcher.cjs +2 -3
- package/dist/cjs/async-batcher.cjs.map +1 -1
- package/dist/cjs/async-batcher.d.cts +7 -11
- package/dist/cjs/async-debouncer.cjs +9 -15
- package/dist/cjs/async-debouncer.cjs.map +1 -1
- package/dist/cjs/async-debouncer.d.cts +3 -3
- package/dist/cjs/async-queuer.cjs +3 -3
- package/dist/cjs/async-queuer.cjs.map +1 -1
- package/dist/cjs/async-queuer.d.cts +4 -4
- package/dist/cjs/async-rate-limiter.cjs +4 -4
- package/dist/cjs/async-rate-limiter.cjs.map +1 -1
- package/dist/cjs/async-rate-limiter.d.cts +4 -4
- package/dist/cjs/async-throttler.cjs +10 -16
- package/dist/cjs/async-throttler.cjs.map +1 -1
- package/dist/cjs/async-throttler.d.cts +3 -3
- package/dist/cjs/batcher.cjs +1 -1
- package/dist/cjs/batcher.cjs.map +1 -1
- package/dist/cjs/batcher.d.cts +3 -3
- package/dist/cjs/debouncer.cjs +1 -1
- package/dist/cjs/debouncer.cjs.map +1 -1
- package/dist/cjs/debouncer.d.cts +1 -1
- package/dist/cjs/queuer.cjs.map +1 -1
- package/dist/cjs/queuer.d.cts +2 -2
- package/dist/cjs/rate-limiter.cjs +1 -1
- package/dist/cjs/rate-limiter.cjs.map +1 -1
- package/dist/cjs/rate-limiter.d.cts +1 -1
- package/dist/cjs/throttler.cjs +1 -1
- package/dist/cjs/throttler.cjs.map +1 -1
- package/dist/cjs/throttler.d.cts +1 -1
- package/dist/esm/async-batcher.d.ts +7 -11
- package/dist/esm/async-batcher.js +2 -3
- package/dist/esm/async-batcher.js.map +1 -1
- package/dist/esm/async-debouncer.d.ts +3 -3
- package/dist/esm/async-debouncer.js +9 -15
- package/dist/esm/async-debouncer.js.map +1 -1
- package/dist/esm/async-queuer.d.ts +4 -4
- package/dist/esm/async-queuer.js +3 -3
- package/dist/esm/async-queuer.js.map +1 -1
- package/dist/esm/async-rate-limiter.d.ts +4 -4
- package/dist/esm/async-rate-limiter.js +4 -4
- package/dist/esm/async-rate-limiter.js.map +1 -1
- package/dist/esm/async-throttler.d.ts +3 -3
- package/dist/esm/async-throttler.js +10 -16
- package/dist/esm/async-throttler.js.map +1 -1
- package/dist/esm/batcher.d.ts +3 -3
- package/dist/esm/batcher.js +1 -1
- package/dist/esm/batcher.js.map +1 -1
- package/dist/esm/debouncer.d.ts +1 -1
- package/dist/esm/debouncer.js +1 -1
- package/dist/esm/debouncer.js.map +1 -1
- package/dist/esm/queuer.d.ts +2 -2
- package/dist/esm/queuer.js.map +1 -1
- package/dist/esm/rate-limiter.d.ts +1 -1
- package/dist/esm/rate-limiter.js +1 -1
- package/dist/esm/rate-limiter.js.map +1 -1
- package/dist/esm/throttler.d.ts +1 -1
- package/dist/esm/throttler.js +1 -1
- package/dist/esm/throttler.js.map +1 -1
- package/package.json +1 -1
- package/src/async-batcher.ts +15 -21
- package/src/async-debouncer.ts +21 -17
- package/src/async-queuer.ts +8 -8
- package/src/async-rate-limiter.ts +15 -7
- package/src/async-throttler.ts +20 -17
- package/src/batcher.ts +4 -4
- package/src/debouncer.ts +2 -2
- package/src/queuer.ts +2 -2
- package/src/rate-limiter.ts +2 -2
- package/src/throttler.ts +2 -2
package/src/debouncer.ts
CHANGED
|
@@ -60,7 +60,7 @@ export interface DebouncerOptions<TFn extends AnyFunction> {
|
|
|
60
60
|
/**
|
|
61
61
|
* Callback function that is called after the function is executed
|
|
62
62
|
*/
|
|
63
|
-
onExecute?: (debouncer: Debouncer<TFn>) => void
|
|
63
|
+
onExecute?: (args: Parameters<TFn>, debouncer: Debouncer<TFn>) => void
|
|
64
64
|
/**
|
|
65
65
|
* Whether to execute on the trailing edge of the timeout.
|
|
66
66
|
* Defaults to true.
|
|
@@ -217,7 +217,7 @@ export class Debouncer<TFn extends AnyFunction> {
|
|
|
217
217
|
isPending: false,
|
|
218
218
|
lastArgs: undefined,
|
|
219
219
|
})
|
|
220
|
-
this.options.onExecute?.(this)
|
|
220
|
+
this.options.onExecute?.(args, this)
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
/**
|
package/src/queuer.ts
CHANGED
|
@@ -225,7 +225,7 @@ export type QueuePosition = 'front' | 'back'
|
|
|
225
225
|
* const autoQueue = new Queuer<number>((n) => console.log(n), {
|
|
226
226
|
* started: true, // Begin processing immediately
|
|
227
227
|
* wait: 1000, // Wait 1s between items
|
|
228
|
-
* onExecute: (item) => console.log(`Processed ${item}`)
|
|
228
|
+
* onExecute: (item, queuer) => console.log(`Processed ${item}`)
|
|
229
229
|
* });
|
|
230
230
|
* autoQueue.addItem(1); // Will process after 1s
|
|
231
231
|
* autoQueue.addItem(2); // Will process 1s after first item
|
|
@@ -516,7 +516,7 @@ export class Queuer<TValue> {
|
|
|
516
516
|
}
|
|
517
517
|
|
|
518
518
|
/**
|
|
519
|
-
* Processes all items in the queue as a batch using the provided function
|
|
519
|
+
* Processes all items in the queue as a batch using the provided function as an argument
|
|
520
520
|
* The queue is cleared after processing
|
|
521
521
|
*/
|
|
522
522
|
flushAsBatch = (batchFunction: (items: Array<TValue>) => void): void => {
|
package/src/rate-limiter.ts
CHANGED
|
@@ -56,7 +56,7 @@ export interface RateLimiterOptions<TFn extends AnyFunction> {
|
|
|
56
56
|
/**
|
|
57
57
|
* Callback function that is called after the function is executed
|
|
58
58
|
*/
|
|
59
|
-
onExecute?: (rateLimiter: RateLimiter<TFn>) => void
|
|
59
|
+
onExecute?: (args: Parameters<TFn>, rateLimiter: RateLimiter<TFn>) => void
|
|
60
60
|
/**
|
|
61
61
|
* Optional callback function that is called when an execution is rejected due to rate limiting
|
|
62
62
|
*/
|
|
@@ -240,7 +240,7 @@ export class RateLimiter<TFn extends AnyFunction> {
|
|
|
240
240
|
this.#setState({
|
|
241
241
|
executionCount: this.store.state.executionCount + 1,
|
|
242
242
|
})
|
|
243
|
-
this.options.onExecute?.(this)
|
|
243
|
+
this.options.onExecute?.(args, this)
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
#getExecutionTimesInWindow = (): Array<number> => {
|
package/src/throttler.ts
CHANGED
|
@@ -64,7 +64,7 @@ export interface ThrottlerOptions<TFn extends AnyFunction> {
|
|
|
64
64
|
/**
|
|
65
65
|
* Callback function that is called after the function is executed
|
|
66
66
|
*/
|
|
67
|
-
onExecute?: (throttler: Throttler<TFn>) => void
|
|
67
|
+
onExecute?: (args: Parameters<TFn>, throttler: Throttler<TFn>) => void
|
|
68
68
|
/**
|
|
69
69
|
* Whether to execute on the trailing edge of the timeout.
|
|
70
70
|
* Defaults to true.
|
|
@@ -245,7 +245,7 @@ export class Throttler<TFn extends AnyFunction> {
|
|
|
245
245
|
isPending: false,
|
|
246
246
|
lastArgs: undefined,
|
|
247
247
|
})
|
|
248
|
-
this.options.onExecute?.(this)
|
|
248
|
+
this.options.onExecute?.(args, this)
|
|
249
249
|
setTimeout(() => {
|
|
250
250
|
if (!this.store.state.isPending) {
|
|
251
251
|
this.#setState({ nextExecutionTime: undefined })
|