Skip to content

abortableAll<const T>

An abort-scoped Promise.all.

Calls executor with a child abort signal, which aborts when abortSignal aborts or when any task rejects. The returned promise settles only once every task has settled, so no task outlives the group: it resolves with every task’s value, in task order, or rejects with the first rejection, where a rejection that is not an AbortError wins over an AbortError that a sibling abort caused.

The tasks must honour the child signal, rejecting once it aborts, either at once or after their cleanup. A task that ignores it keeps the group waiting for it.

Import:

import { abortableAll } from '@mnaoumov/typescript-lib/abortable-tasks';

Example:

const [user, settings] = await abortableAll(abortSignal, (childAbortSignal) => [
fetchUser(childAbortSignal),
fetchSettings(childAbortSignal)
]);

Signature:

function abortableAll(abortSignal: AbortSignal, executor: AbortableTasksExecutor<T>): Promise<AbortableAllResult<T>>

Parameters:

Parameter Type Description
abortSignal AbortSignal Aborts the whole group. If it is already aborted, executor is never called.
executor AbortableTasksExecutor<T> Builds the tasks from the child abort signal.

Returns: Promise<AbortableAllResult<T>> — A Promise that resolves with the tasks’ values, or rejects with the first rejection or with the reason of abortSignal if it was already aborted.

Example:

const [user, settings] = await abortableAll(abortSignal, (childAbortSignal) => [
fetchUser(childAbortSignal),
fetchSettings(childAbortSignal)
]);

Links to this page: