API reference › @evolu/common › Task
JavaScript-native structured concurrency.
Core Types
| Name | Description |
|---|---|
| AbortError | Error returned when a Task is aborted via AbortSignal. |
| Fiber | Fiber is a handle to a running Task that can be awaited, aborted, or disposed. |
| Run | Runs a Task with structured concurrency semantics. |
| RunSnapshot | A recursive snapshot of a Run tree. |
| NextTask | A Task that can complete with a value, signal done, or fail. |
| RunState | The lifecycle state of a Run. |
| Task | JavaScript-native structured concurrency. |
| AbortError | Error returned when a Task is aborted via AbortSignal. |
Creating Run
| Name | Description |
|---|---|
| CreateRun | Factory type for creating root Run instances. |
| RunStoppedError | Abort reason indicating a Run can no longer start new Tasks. |
| createRun | Creates root Run. |
| runStoppedError | Shared RunStoppedError instance used as the default AbortError.reason when a Task is started on a non-running Run. |
| RunStoppedError | Abort reason indicating a Run can no longer start new Tasks. |
Abort masking
| Name | Description |
|---|---|
| AbortMask | Abort mask depth for a Run or Fiber. |
| AbortMask | Abort mask depth for a Run or Fiber. |
| unabortable | Makes a Task unabortable. |
| unabortableMask | Like unabortable, but provides restore to restore abortability for specific tasks. |
Composition
| Name | Description |
|---|---|
| AllAbortError | Abort reason used by all when aborting remaining tasks. |
| AllSettledAbortError | Abort reason used by allSettled when aborted externally. |
| AnyAbortError | Abort reason used by any when aborting remaining tasks. |
| CollectOptions | Options for all, allSettled, map, and mapSettled. |
| FetchError | Error returned when a fetch Task fails. |
| MapAbortError | Abort reason used by map when aborting remaining tasks. |
| RaceLostError | Abort reason for tasks that lose a race. |
| RepeatAttempt | Info passed to repeat RepeatOptions.onRepeat callback. |
| RepeatOptions | Options for repeat. |
| RetryAttempt | Info passed to retry RetryOptions.onRetry callback. |
| RetryError | Error returned when all retry attempts are exhausted. |
| RetryOptions | Options for retry. |
| TimeoutError | Typed error returned by timeout when a task exceeds its time limit. |
| allAbortError | AllAbortError used as abort reason in all. |
| AllAbortError | Abort reason used by all when aborting remaining tasks. |
| allSettledAbortError | AllSettledAbortError used as abort reason in allSettled. |
| AllSettledAbortError | Abort reason used by allSettled when aborted externally. |
| anyAbortError | AnyAbortError used as abort reason in any. |
| AnyAbortError | Abort reason used by any when aborting remaining tasks. |
| FetchError | Error returned when a fetch Task fails. |
| mapAbortError | MapAbortError used as abort reason in map. |
| MapAbortError | Abort reason used by map when aborting remaining tasks. |
| raceLostError | RaceLostError used as abort reason in race. |
| RaceLostError | Abort reason for tasks that lose a race. |
| timeoutError | TimeoutError used as abort reason in timeout. |
| TimeoutError | Typed error returned by timeout when a task exceeds its time limit. |
| yieldNow | Yields execution to allow other work to proceed. |
| all | Fails fast on first error across multiple Tasks. |
| allSettled | Completes all Tasks regardless of individual failures. |
| any | Returns the first Task that succeeds. |
| callback | Creates a Task from a callback-based API. |
| concurrently | Runs tasks concurrently instead of sequentially. |
| fetch | Creates a Task that wraps the native Fetch API. |
| map | Maps values to Tasks, failing fast on first error. |
| mapSettled | Maps values to Tasks, completing all regardless of failures. |
| race | Returns a Task that completes first. |
| repeat | Repeats a Task according to a Schedule. |
| retry | Wraps a Task with retry logic. |
| sleep | Pauses execution for a specified duration. |
| timeout | Wraps a Task with a time limit. |
Concurrency primitives
| Name | Description |
|---|---|
| Deferred | A value that can be resolved later. |
| DeferredDisposedError | Abort reason used when a Deferred is disposed. |
| Gate | A blocking Task — like a gate. |
| LeaderLock | Cross-platform leader lock abstraction. |
| LeaderLockDep | - |
| Mutex | A mutex (mutual exclusion) that ensures only one Task runs at a time. |
| MutexByKey | A keyed Mutex registry. |
| MutexRef | Ref protected by a Mutex. |
| Semaphore | A semaphore that limits the number of concurrent Tasks. |
| SemaphoreByKey | A keyed Semaphore registry. |
| SemaphoreDisposedError | Abort reason used when a Semaphore is disposed. |
| Concurrency | Maximum number of concurrent Tasks. |
| deferredDisposedError | DeferredDisposedError used as abort reason in createDeferred. |
| DeferredDisposedError | Abort reason used when a Deferred is disposed. |
| semaphoreDisposedError | SemaphoreDisposedError used as abort reason in createSemaphore. |
| SemaphoreDisposedError | Abort reason used when a Semaphore is disposed. |
| createDeferred | Creates a Deferred. |
| createGate | Creates a Gate that starts closed. |
| createInMemoryLeaderLock | Creates an in-process LeaderLock. |
| createMutex | Creates a Mutex. |
| createMutexByKey | Creates a MutexByKey. |
| createMutexRef | Creates a MutexRef with the given initial immutable value. |
| createSemaphore | Creates a Semaphore that limits concurrent Tasks. |
| createSemaphoreByKey | Creates a SemaphoreByKey. |
Monitoring
| Name | Description |
|---|---|
| RunConfig | Configuration for Run behavior. |
| RunEvent | Events emitted by a Run for monitoring and debugging. |
| RunEventData | The event-specific payload of a RunEvent. |
| RunSnapshotState | RunSnapshot state Type. |
| RunEvent | Events emitted by a Run for monitoring and debugging. |
| RunEventData | The event-specific payload of a RunEvent. |
| RunSnapshotState | RunSnapshot state Type. |
Type utilities
| Type Alias | Description |
|---|---|
| AnyTask | Shorthand for a Task with any type parameters. |
| InferFiberDeps | Extracts the deps type from a Fiber. |
| InferFiberErr | Extracts the error type from a Fiber. |
| InferFiberOk | Extracts the value type from a Fiber. |
| InferTaskDeps | Extracts the deps type from a Task. |
| InferTaskDone | Extracts the done value type from a NextTask. |
| InferTaskErr | Extracts the error type from a Task. |
| InferTaskOk | Extracts the value type from a Task. |
Interfaces
| Interface | Description |
|---|---|
| CreateMutexByKeyOptions | Options for createMutexByKey. |
| CreateSemaphoreByKeyOptions | Options for createSemaphoreByKey. |
| RunConfigDep | - |
| RunStateDisposing | Base interface for objects with a discriminant type property. |
| RunStateRunning | Base interface for objects with a discriminant type property. |
| RunStateSettled | Base interface for objects with a discriminant type property. |
| SemaphoreSnapshot | Snapshot returned by Semaphore.snapshot. |
Type Aliases
| Type Alias | Description |
|---|---|
| AnyAllFailed | Tie-breaker for any when all tasks fail. |
| RunDeps | Default deps provided by createRun. |