API reference › @evolu/common › Task › any
function any<T, E, D>(
tasks: readonly [Task<T, E, D>, Task<T, E, D>],
options?: {
allFailed?: AnyAllFailed;
},
): Task<T, E, D>;
Defined in: packages/common/src/Task.ts:3479
Returns the first Task that succeeds.
Like Promise.any, the first Task to succeed wins. All other Tasks are aborted. If all Tasks fail, returns the last error (by input order).
Sequential by default. Use concurrently for concurrent execution.
Think of it like Array.prototype.some() — it stops on the first success.
This is in contrast to race, which returns the first task to complete
(whether success or failure).
Example
// Try multiple endpoints concurrently, first success wins
const result = await run(
concurrently(any([fetchFromPrimary, fetchFromSecondary, fetchFromTertiary])),
);