@tanstack/pacer 0.12.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 +3 -7
- package/dist/cjs/async-debouncer.cjs +2 -2
- package/dist/cjs/async-debouncer.cjs.map +1 -1
- package/dist/cjs/async-debouncer.d.cts +2 -2
- package/dist/cjs/async-queuer.cjs +2 -2
- package/dist/cjs/async-queuer.cjs.map +1 -1
- package/dist/cjs/async-queuer.d.cts +2 -2
- package/dist/cjs/async-rate-limiter.cjs +2 -2
- package/dist/cjs/async-rate-limiter.cjs.map +1 -1
- package/dist/cjs/async-rate-limiter.d.cts +2 -2
- package/dist/cjs/async-throttler.cjs +2 -2
- package/dist/cjs/async-throttler.cjs.map +1 -1
- package/dist/cjs/async-throttler.d.cts +2 -2
- 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 +1 -1
- 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 +3 -7
- package/dist/esm/async-batcher.js +2 -3
- package/dist/esm/async-batcher.js.map +1 -1
- package/dist/esm/async-debouncer.d.ts +2 -2
- package/dist/esm/async-debouncer.js +2 -2
- package/dist/esm/async-debouncer.js.map +1 -1
- package/dist/esm/async-queuer.d.ts +2 -2
- package/dist/esm/async-queuer.js +2 -2
- package/dist/esm/async-queuer.js.map +1 -1
- package/dist/esm/async-rate-limiter.d.ts +2 -2
- package/dist/esm/async-rate-limiter.js +2 -2
- package/dist/esm/async-rate-limiter.js.map +1 -1
- package/dist/esm/async-throttler.d.ts +2 -2
- package/dist/esm/async-throttler.js +2 -2
- 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 +1 -1
- 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 +9 -15
- package/src/async-debouncer.ts +8 -4
- package/src/async-queuer.ts +4 -4
- package/src/async-rate-limiter.ts +7 -3
- package/src/async-throttler.ts +7 -3
- package/src/batcher.ts +4 -4
- package/src/debouncer.ts +2 -2
- package/src/queuer.ts +1 -1
- package/src/rate-limiter.ts +2 -2
- package/src/throttler.ts +2 -2
package/src/batcher.ts
CHANGED
|
@@ -66,7 +66,7 @@ export interface BatcherOptions<TValue> {
|
|
|
66
66
|
/**
|
|
67
67
|
* Callback fired after a batch is processed
|
|
68
68
|
*/
|
|
69
|
-
onExecute?: (batcher: Batcher<TValue>) => void
|
|
69
|
+
onExecute?: (batch: Array<TValue>, batcher: Batcher<TValue>) => void
|
|
70
70
|
/**
|
|
71
71
|
* Callback fired after items are added to the batcher
|
|
72
72
|
*/
|
|
@@ -124,7 +124,7 @@ const defaultOptions: BatcherOptionsWithOptionalCallbacks<any> = {
|
|
|
124
124
|
* {
|
|
125
125
|
* maxSize: 5,
|
|
126
126
|
* wait: 2000,
|
|
127
|
-
* onExecute: (batcher) => console.log('Batch executed:',
|
|
127
|
+
* onExecute: (batch, batcher) => console.log('Batch executed:', batch)
|
|
128
128
|
* }
|
|
129
129
|
* );
|
|
130
130
|
*
|
|
@@ -228,7 +228,7 @@ export class Batcher<TValue> {
|
|
|
228
228
|
executionCount: this.store.state.executionCount + 1,
|
|
229
229
|
totalItemsProcessed: this.store.state.totalItemsProcessed + batch.length,
|
|
230
230
|
})
|
|
231
|
-
this.options.onExecute?.(this)
|
|
231
|
+
this.options.onExecute?.(batch, this)
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
/**
|
|
@@ -278,7 +278,7 @@ export class Batcher<TValue> {
|
|
|
278
278
|
* (items) => console.log('Processing:', items),
|
|
279
279
|
* {
|
|
280
280
|
* maxSize: 3,
|
|
281
|
-
* onExecute: (batcher) => console.log('Batch executed')
|
|
281
|
+
* onExecute: (batch, batcher) => console.log('Batch executed:', batch)
|
|
282
282
|
* }
|
|
283
283
|
* );
|
|
284
284
|
*
|
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
|
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 })
|