abortable-tasks
Abort-scoped versions of Promise.all and Promise.race: each task gets a child abort signal, and the group aborts the tasks still running once its outcome is known.
Adapted from abort-controller-x’s all and race (MIT, see THIRD-PARTY-NOTICES.md), with the native AbortError DOMException as the sibling abort reason instead of a custom error class.
Functions
Section titled “Functions”| Function | Description |
|---|---|
| abortableAll | 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. |
| abortableRace | An abort-scoped Promise.race. Calls executor with a child abort signal, which aborts when abortSignal aborts or when the first task settles. The returned promise settles only once every task has settled, so no task outlives the group, and it settles like the first task that settled. One exception keeps a real failure from being swallowed: a later rejection that is not an AbortError wins over a first task that fulfilled or rejected with an AbortError. 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. With no tasks, the returned promise settles only when abortSignal aborts, rejecting with its reason, as Promise.race([]) never settles. |
| Type | Description |
|---|---|
| AbortableAllResult | The result of abortableAll: the awaited value of each task, in task order. |
| AbortableTasksExecutor | Builds the group’s tasks from the child abort signal they must honour. |