API reference@evolu/common › Task

JavaScript-native structured concurrency.

Core Types

NameDescription
AbortErrorError returned when a Task is aborted via AbortSignal.
FiberFiber is a handle to a running Task that can be awaited, aborted, or disposed.
RunRuns a Task with structured concurrency semantics.
RunSnapshotA recursive snapshot of a Run tree.
NextTaskA Task that can complete with a value, signal done, or fail.
RunStateThe lifecycle state of a Run.
TaskJavaScript-native structured concurrency.
AbortErrorError returned when a Task is aborted via AbortSignal.

Creating Run

NameDescription
CreateRunFactory type for creating root Run instances.
RunStoppedErrorAbort reason indicating a Run can no longer start new Tasks.
createRunCreates root Run.
runStoppedErrorShared RunStoppedError instance used as the default AbortError.reason when a Task is started on a non-running Run.
RunStoppedErrorAbort reason indicating a Run can no longer start new Tasks.

Abort masking

NameDescription
AbortMaskAbort mask depth for a Run or Fiber.
AbortMaskAbort mask depth for a Run or Fiber.
unabortableMakes a Task unabortable.
unabortableMaskLike unabortable, but provides restore to restore abortability for specific tasks.

Composition

NameDescription
AllAbortErrorAbort reason used by all when aborting remaining tasks.
AllSettledAbortErrorAbort reason used by allSettled when aborted externally.
AnyAbortErrorAbort reason used by any when aborting remaining tasks.
CollectOptionsOptions for all, allSettled, map, and mapSettled.
FetchErrorError returned when a fetch Task fails.
MapAbortErrorAbort reason used by map when aborting remaining tasks.
RaceLostErrorAbort reason for tasks that lose a race.
RepeatAttemptInfo passed to repeat RepeatOptions.onRepeat callback.
RepeatOptionsOptions for repeat.
RetryAttemptInfo passed to retry RetryOptions.onRetry callback.
RetryErrorError returned when all retry attempts are exhausted.
RetryOptionsOptions for retry.
TimeoutErrorTyped error returned by timeout when a task exceeds its time limit.
allAbortErrorAllAbortError used as abort reason in all.
AllAbortErrorAbort reason used by all when aborting remaining tasks.
allSettledAbortErrorAllSettledAbortError used as abort reason in allSettled.
AllSettledAbortErrorAbort reason used by allSettled when aborted externally.
anyAbortErrorAnyAbortError used as abort reason in any.
AnyAbortErrorAbort reason used by any when aborting remaining tasks.
FetchErrorError returned when a fetch Task fails.
mapAbortErrorMapAbortError used as abort reason in map.
MapAbortErrorAbort reason used by map when aborting remaining tasks.
raceLostErrorRaceLostError used as abort reason in race.
RaceLostErrorAbort reason for tasks that lose a race.
timeoutErrorTimeoutError used as abort reason in timeout.
TimeoutErrorTyped error returned by timeout when a task exceeds its time limit.
yieldNowYields execution to allow other work to proceed.
allFails fast on first error across multiple Tasks.
allSettledCompletes all Tasks regardless of individual failures.
anyReturns the first Task that succeeds.
callbackCreates a Task from a callback-based API.
concurrentlyRuns tasks concurrently instead of sequentially.
fetchCreates a Task that wraps the native Fetch API.
mapMaps values to Tasks, failing fast on first error.
mapSettledMaps values to Tasks, completing all regardless of failures.
raceReturns a Task that completes first.
repeatRepeats a Task according to a Schedule.
retryWraps a Task with retry logic.
sleepPauses execution for a specified duration.
timeoutWraps a Task with a time limit.

Concurrency primitives

NameDescription
DeferredA value that can be resolved later.
DeferredDisposedErrorAbort reason used when a Deferred is disposed.
GateA blocking Task — like a gate.
LeaderLockCross-platform leader lock abstraction.
LeaderLockDep-
MutexA mutex (mutual exclusion) that ensures only one Task runs at a time.
MutexByKeyA keyed Mutex registry.
MutexRefRef protected by a Mutex.
SemaphoreA semaphore that limits the number of concurrent Tasks.
SemaphoreByKeyA keyed Semaphore registry.
SemaphoreDisposedErrorAbort reason used when a Semaphore is disposed.
ConcurrencyMaximum number of concurrent Tasks.
deferredDisposedErrorDeferredDisposedError used as abort reason in createDeferred.
DeferredDisposedErrorAbort reason used when a Deferred is disposed.
semaphoreDisposedErrorSemaphoreDisposedError used as abort reason in createSemaphore.
SemaphoreDisposedErrorAbort reason used when a Semaphore is disposed.
createDeferredCreates a Deferred.
createGateCreates a Gate that starts closed.
createInMemoryLeaderLockCreates an in-process LeaderLock.
createMutexCreates a Mutex.
createMutexByKeyCreates a MutexByKey.
createMutexRefCreates a MutexRef with the given initial immutable value.
createSemaphoreCreates a Semaphore that limits concurrent Tasks.
createSemaphoreByKeyCreates a SemaphoreByKey.

Monitoring

NameDescription
RunConfigConfiguration for Run behavior.
RunEventEvents emitted by a Run for monitoring and debugging.
RunEventDataThe event-specific payload of a RunEvent.
RunSnapshotStateRunSnapshot state Type.
RunEventEvents emitted by a Run for monitoring and debugging.
RunEventDataThe event-specific payload of a RunEvent.
RunSnapshotStateRunSnapshot state Type.

Type utilities

Type AliasDescription
AnyTaskShorthand for a Task with any type parameters.
InferFiberDepsExtracts the deps type from a Fiber.
InferFiberErrExtracts the error type from a Fiber.
InferFiberOkExtracts the value type from a Fiber.
InferTaskDepsExtracts the deps type from a Task.
InferTaskDoneExtracts the done value type from a NextTask.
InferTaskErrExtracts the error type from a Task.
InferTaskOkExtracts the value type from a Task.

Interfaces

InterfaceDescription
CreateMutexByKeyOptionsOptions for createMutexByKey.
CreateSemaphoreByKeyOptionsOptions for createSemaphoreByKey.
RunConfigDep-
RunStateDisposingBase interface for objects with a discriminant type property.
RunStateRunningBase interface for objects with a discriminant type property.
RunStateSettledBase interface for objects with a discriminant type property.
SemaphoreSnapshotSnapshot returned by Semaphore.snapshot.

Type Aliases

Type AliasDescription
AnyAllFailedTie-breaker for any when all tasks fail.
RunDepsDefault deps provided by createRun.