@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.
Files changed (69) hide show
  1. package/dist/cjs/async-batcher.cjs +2 -3
  2. package/dist/cjs/async-batcher.cjs.map +1 -1
  3. package/dist/cjs/async-batcher.d.cts +7 -11
  4. package/dist/cjs/async-debouncer.cjs +9 -15
  5. package/dist/cjs/async-debouncer.cjs.map +1 -1
  6. package/dist/cjs/async-debouncer.d.cts +3 -3
  7. package/dist/cjs/async-queuer.cjs +3 -3
  8. package/dist/cjs/async-queuer.cjs.map +1 -1
  9. package/dist/cjs/async-queuer.d.cts +4 -4
  10. package/dist/cjs/async-rate-limiter.cjs +4 -4
  11. package/dist/cjs/async-rate-limiter.cjs.map +1 -1
  12. package/dist/cjs/async-rate-limiter.d.cts +4 -4
  13. package/dist/cjs/async-throttler.cjs +10 -16
  14. package/dist/cjs/async-throttler.cjs.map +1 -1
  15. package/dist/cjs/async-throttler.d.cts +3 -3
  16. package/dist/cjs/batcher.cjs +1 -1
  17. package/dist/cjs/batcher.cjs.map +1 -1
  18. package/dist/cjs/batcher.d.cts +3 -3
  19. package/dist/cjs/debouncer.cjs +1 -1
  20. package/dist/cjs/debouncer.cjs.map +1 -1
  21. package/dist/cjs/debouncer.d.cts +1 -1
  22. package/dist/cjs/queuer.cjs.map +1 -1
  23. package/dist/cjs/queuer.d.cts +2 -2
  24. package/dist/cjs/rate-limiter.cjs +1 -1
  25. package/dist/cjs/rate-limiter.cjs.map +1 -1
  26. package/dist/cjs/rate-limiter.d.cts +1 -1
  27. package/dist/cjs/throttler.cjs +1 -1
  28. package/dist/cjs/throttler.cjs.map +1 -1
  29. package/dist/cjs/throttler.d.cts +1 -1
  30. package/dist/esm/async-batcher.d.ts +7 -11
  31. package/dist/esm/async-batcher.js +2 -3
  32. package/dist/esm/async-batcher.js.map +1 -1
  33. package/dist/esm/async-debouncer.d.ts +3 -3
  34. package/dist/esm/async-debouncer.js +9 -15
  35. package/dist/esm/async-debouncer.js.map +1 -1
  36. package/dist/esm/async-queuer.d.ts +4 -4
  37. package/dist/esm/async-queuer.js +3 -3
  38. package/dist/esm/async-queuer.js.map +1 -1
  39. package/dist/esm/async-rate-limiter.d.ts +4 -4
  40. package/dist/esm/async-rate-limiter.js +4 -4
  41. package/dist/esm/async-rate-limiter.js.map +1 -1
  42. package/dist/esm/async-throttler.d.ts +3 -3
  43. package/dist/esm/async-throttler.js +10 -16
  44. package/dist/esm/async-throttler.js.map +1 -1
  45. package/dist/esm/batcher.d.ts +3 -3
  46. package/dist/esm/batcher.js +1 -1
  47. package/dist/esm/batcher.js.map +1 -1
  48. package/dist/esm/debouncer.d.ts +1 -1
  49. package/dist/esm/debouncer.js +1 -1
  50. package/dist/esm/debouncer.js.map +1 -1
  51. package/dist/esm/queuer.d.ts +2 -2
  52. package/dist/esm/queuer.js.map +1 -1
  53. package/dist/esm/rate-limiter.d.ts +1 -1
  54. package/dist/esm/rate-limiter.js +1 -1
  55. package/dist/esm/rate-limiter.js.map +1 -1
  56. package/dist/esm/throttler.d.ts +1 -1
  57. package/dist/esm/throttler.js +1 -1
  58. package/dist/esm/throttler.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/async-batcher.ts +15 -21
  61. package/src/async-debouncer.ts +21 -17
  62. package/src/async-queuer.ts +8 -8
  63. package/src/async-rate-limiter.ts +15 -7
  64. package/src/async-throttler.ts +20 -17
  65. package/src/batcher.ts +4 -4
  66. package/src/debouncer.ts +2 -2
  67. package/src/queuer.ts +2 -2
  68. package/src/rate-limiter.ts +2 -2
  69. 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 => {
@@ -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 })