Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unify-execution-count-naming.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/pacer': minor
---

breaking: rename `executeCount` to `executionCount` in `AsyncBatcherState` and `AsyncQueuerState` for consistency with all other utilities (`BatcherState`, `QueuerState`, `DebouncerState`, `ThrottlerState`, `RateLimiterState`, and `AsyncRetryerState` all use `executionCount`). The `getAbortSignal(executionCount?)` parameter on AsyncBatcher and AsyncQueuer is renamed accordingly. Pure rename, no behavior change — update any state selectors, `initialState` values, or callbacks reading `executeCount` to use `executionCount` (fixes #253)
2 changes: 1 addition & 1 deletion docs/framework/angular/guides/async-batching.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const batcher = injectAsyncBatcher(
batcher.abort()
```

When executions overlap, pass an `executeCount` to `getAbortSignal()` when you need a specific execution's signal.
When executions overlap, pass an `executionCount` to `getAbortSignal()` when you need a specific execution's signal.

### Resetting safely

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/angular/guides/async-queuing.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const queue = injectAsyncQueuer(
queue.abort()
```

When multiple executions overlap, pass an `executeCount` to `getAbortSignal()` when you need a specific execution's signal.
When multiple executions overlap, pass an `executionCount` to `getAbortSignal()` when you need a specific execution's signal.

### Resetting safely

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/preact/guides/async-batching.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const batcher = useAsyncBatcher(
batcher.abort()
```

When executions overlap, pass an `executeCount` to `getAbortSignal()` when you need a specific execution's signal.
When executions overlap, pass an `executionCount` to `getAbortSignal()` when you need a specific execution's signal.

### Resetting safely

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/preact/guides/async-queuing.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const queue = useAsyncQueuer(
queue.abort()
```

When multiple executions overlap, pass an `executeCount` to `getAbortSignal()` when you need a specific execution's signal.
When multiple executions overlap, pass an `executionCount` to `getAbortSignal()` when you need a specific execution's signal.

### Resetting safely

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/guides/async-batching.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const batcher = useAsyncBatcher(
batcher.abort()
```

When executions overlap, pass an `executeCount` to `getAbortSignal()` when you need a specific execution's signal.
When executions overlap, pass an `executionCount` to `getAbortSignal()` when you need a specific execution's signal.

### Resetting safely

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/guides/async-queuing.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const queue = useAsyncQueuer(
queue.abort()
```

When multiple executions overlap, pass an `executeCount` to `getAbortSignal()` when you need a specific execution's signal.
When multiple executions overlap, pass an `executionCount` to `getAbortSignal()` when you need a specific execution's signal.

### Resetting safely

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/solid/guides/async-batching.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const batcher = createAsyncBatcher(
batcher.abort()
```

When executions overlap, pass an `executeCount` to `getAbortSignal()` when you need a specific execution's signal.
When executions overlap, pass an `executionCount` to `getAbortSignal()` when you need a specific execution's signal.

### Resetting safely

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/solid/guides/async-queuing.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const queue = createAsyncQueuer(
queue.abort()
```

When multiple executions overlap, pass an `executeCount` to `getAbortSignal()` when you need a specific execution's signal.
When multiple executions overlap, pass an `executionCount` to `getAbortSignal()` when you need a specific execution's signal.

### Resetting safely

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/vanilla/guides/async-batching.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const batcher = new AsyncBatcher(
batcher.abort()
```

When executions overlap, pass an `executeCount` to `getAbortSignal()` when you need a specific execution's signal.
When executions overlap, pass an `executionCount` to `getAbortSignal()` when you need a specific execution's signal.

### Resetting safely

Expand Down
2 changes: 1 addition & 1 deletion docs/framework/vanilla/guides/async-queuing.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const queue = new AsyncQueuer(
queue.abort()
```

When multiple executions overlap, pass an `executeCount` to `getAbortSignal()` when you need a specific execution's signal.
When multiple executions overlap, pass an `executionCount` to `getAbortSignal()` when you need a specific execution's signal.

### Resetting safely

Expand Down
6 changes: 3 additions & 3 deletions docs/reference/classes/AsyncBatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,18 @@ Processes the current batch of items immediately
### getAbortSignal()

```ts
getAbortSignal(executeCount?): AbortSignal | null;
getAbortSignal(executionCount?): AbortSignal | null;
```

Defined in: [async-batcher.ts:483](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L483)

Returns the AbortSignal for a specific execution.
If no executeCount is provided, returns the signal for the most recent execution.
If no executionCount is provided, returns the signal for the most recent execution.
Returns null if no execution is found or not currently executing.

#### Parameters

##### executeCount?
##### executionCount?

`number`

Expand Down
6 changes: 3 additions & 3 deletions docs/reference/classes/AsyncQueuer.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ The queue is cleared after processing
### getAbortSignal()

```ts
getAbortSignal(executeCount?): AbortSignal | null;
getAbortSignal(executionCount?): AbortSignal | null;
```

Defined in: [async-queuer.ts:889](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L889)

Returns the AbortSignal for a specific execution.
If no executeCount is provided, returns the signal for the most recent execution.
If no executionCount is provided, returns the signal for the most recent execution.
Returns null if no execution is found or not currently executing.

#### Parameters

##### executeCount?
##### executionCount?

`number`

Expand Down
6 changes: 3 additions & 3 deletions docs/reference/interfaces/AsyncBatcherState.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ Number of batch executions that have resulted in errors

***

### executeCount
### executionCount

```ts
executeCount: number;
executionCount: number;
```

Defined in: [async-batcher.ts:16](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L16)

Number of batch executions that have been executed
Number of batch executions that have been started

***

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/interfaces/AsyncQueuerState.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ Number of task executions that have resulted in errors

***

### executeCount
### executionCount

```ts
executeCount: number;
executionCount: number;
```

Defined in: [async-queuer.ts:25](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L25)
Expand Down
22 changes: 11 additions & 11 deletions packages/pacer/src/async-batcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export interface AsyncBatcherState<TValue> {
*/
errorCount: number
/**
* Number of batch executions that have been executed
* Number of batch executions that have been started
*/
executeCount: number
executionCount: number
/**
* Array of items that failed during batch processing
*/
Expand Down Expand Up @@ -67,7 +67,7 @@ export interface AsyncBatcherState<TValue> {
function getDefaultAsyncBatcherState<TValue>(): AsyncBatcherState<TValue> {
return {
errorCount: 0,
executeCount: 0,
executionCount: 0,
failedItems: [],
isEmpty: true,
isExecuting: false,
Expand Down Expand Up @@ -380,19 +380,19 @@ export class AsyncBatcher<TValue> {
return undefined
}

const currentExecuteCount = this.store.state.executeCount + 1
const currentExecutionCount = this.store.state.executionCount + 1
const batch = this.peekAllItems() // copy of the items to be processed (to prevent race conditions)
this.clear() // Clear items before processing to prevent race conditions
this.options.onItemsChange?.(this)

this.#setState({ isExecuting: true, executeCount: currentExecuteCount })
this.#setState({ isExecuting: true, executionCount: currentExecutionCount })

try {
const currentAsyncRetryer = new AsyncRetryer(
this.fn,
this.options.asyncRetryerOptions,
)
this.asyncRetryers.set(currentExecuteCount, currentAsyncRetryer)
this.asyncRetryers.set(currentExecutionCount, currentAsyncRetryer)
const result = await currentAsyncRetryer.execute(batch) // EXECUTE
this.#setState({
totalItemsProcessed:
Expand All @@ -414,7 +414,7 @@ export class AsyncBatcher<TValue> {
}
return undefined
} finally {
this.asyncRetryers.delete(currentExecuteCount) // dispose retryer
this.asyncRetryers.delete(currentExecutionCount) // dispose retryer
this.#setState({
isExecuting: false,
settleCount: this.store.state.settleCount + 1,
Expand Down Expand Up @@ -458,10 +458,10 @@ export class AsyncBatcher<TValue> {

/**
* Returns the AbortSignal for a specific execution.
* If no executeCount is provided, returns the signal for the most recent execution.
* If no executionCount is provided, returns the signal for the most recent execution.
* Returns null if no execution is found or not currently executing.
*
* @param executeCount - Optional specific execution to get signal for
* @param executionCount - Optional specific execution to get signal for
* @example
* ```typescript
* const batcher = new AsyncBatcher(
Expand All @@ -480,8 +480,8 @@ export class AsyncBatcher<TValue> {
* )
* ```
*/
getAbortSignal = (executeCount?: number): AbortSignal | null => {
const count = executeCount ?? this.store.state.executeCount
getAbortSignal = (executionCount?: number): AbortSignal | null => {
const count = executionCount ?? this.store.state.executionCount
const retryer = this.asyncRetryers.get(count)
return retryer?.getAbortSignal() ?? null
}
Expand Down
20 changes: 10 additions & 10 deletions packages/pacer/src/async-queuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface AsyncQueuerState<TValue> {
/**
* Number of times execute has been called
*/
executeCount: number
executionCount: number
/**
* Number of items that have been removed from the queue due to expiration
*/
Expand Down Expand Up @@ -90,7 +90,7 @@ function getDefaultAsyncQueuerState<TValue>(): AsyncQueuerState<TValue> {
activeItems: [],
addItemCount: 0,
errorCount: 0,
executeCount: 0,
executionCount: 0,
expirationCount: 0,
isEmpty: true,
isExecuting: false,
Expand Down Expand Up @@ -636,17 +636,17 @@ export class AsyncQueuer<TValue> {
const item = this.getNextItem(position)

if (item !== undefined) {
const currentExecuteCount = this.store.state.executeCount + 1
const currentExecutionCount = this.store.state.executionCount + 1
this.#setState({
executeCount: currentExecuteCount,
executionCount: currentExecutionCount,
isExecuting: true,
})
try {
const currentAsyncRetryer = new AsyncRetryer(
this.fn,
this.options.asyncRetryerOptions,
)
this.asyncRetryers.set(currentExecuteCount, currentAsyncRetryer)
this.asyncRetryers.set(currentExecutionCount, currentAsyncRetryer)
const lastResult = await currentAsyncRetryer.execute(item) // EXECUTE!
this.#setState({
successCount: this.store.state.successCount + 1,
Expand All @@ -662,7 +662,7 @@ export class AsyncQueuer<TValue> {
throw error
}
} finally {
this.asyncRetryers.delete(currentExecuteCount) // dispose retryer
this.asyncRetryers.delete(currentExecutionCount) // dispose retryer
// remove only one occurrence so duplicate item values keep accurate
// concurrency accounting
const remainingActiveItems = [...this.store.state.activeItems]
Expand Down Expand Up @@ -868,10 +868,10 @@ export class AsyncQueuer<TValue> {

/**
* Returns the AbortSignal for a specific execution.
* If no executeCount is provided, returns the signal for the most recent execution.
* If no executionCount is provided, returns the signal for the most recent execution.
* Returns null if no execution is found or not currently executing.
*
* @param executeCount - Optional specific execution to get signal for
* @param executionCount - Optional specific execution to get signal for
* @example
* ```typescript
* const queuer = new AsyncQueuer(
Expand All @@ -886,8 +886,8 @@ export class AsyncQueuer<TValue> {
* )
* ```
*/
getAbortSignal = (executeCount?: number): AbortSignal | null => {
const count = executeCount ?? this.store.state.executeCount
getAbortSignal = (executionCount?: number): AbortSignal | null => {
const count = executionCount ?? this.store.state.executionCount
const retryer = this.asyncRetryers.get(count)
return retryer?.getAbortSignal() ?? null
}
Expand Down