Overview
ThewithAbort extension adds abort handling to actions and computed atoms, enabling you to cancel ongoing async operations. It supports multiple strategies for handling concurrent calls:
- last-in-win: Abort previous calls when a new one starts (default)
- first-in-win: Ignore new calls while a previous one is running
- manual: No automatic abort, just adds the
abortaction for manual control - finally: Auto-abort all operations when complete
Type Signature
Parameters
string
default:"last-in-win"
The abort strategy to use:
'last-in-win'(default): Aborts previous concurrent calls when a new one starts'first-in-win': Ignores new calls while a previous one is still running'manual': No automatic abort, just adds theabortaction for manual control'finally': Auto-aborts all operations when the action completes
Return Value
Action<[reason?: any]>
Action to manually abort all active operations. Accepts an optional reason parameter.
Examples
Last-in-Win (Default)
Perfect for search/autocomplete where only the latest request matters:First-in-Win
Perfect for preventing duplicate submissions:Manual Abort
Perfect for polling or long-running tasks:Manual Abort - Multiple Concurrent Calls
First-in-Win with Manual Abort
Abort Propagation
Abort signals propagate through nested async operations:Abort in Computed Atoms
Finally Strategy with Race
Abort with Reason
Use Cases
Search/Autocomplete
Form Submission
Infinite Polling
Progressive Data Loading
Integration with AbortController
UseabortVar to access the AbortController:
Related
- withAsync - Async state tracking (automatically includes withAbort when using withAsyncData)
- withAsyncData - Async data management with abort support
- abortVar - Access AbortController in reactive context