[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Task](https://evolu.dev/docs/api-reference/common/Task) › race

```ts
function race<T>(
  tasks: T,
  __namedParameters?: {
    abortReason?: unknown;
  },
): Task<
  InferTaskOk<T[number]>,
  InferTaskErr<T[number]>,
  InferTaskDeps<T[number]>
>;
```

Defined in: [packages/common/src/Task.ts:1823](https://github.com/evoluhq/evolu/blob/e7144e2bbe9069362b62dec1b64a8aa922b8f1b0/packages/common/src/Task.ts#L1823)

Returns a [Task](https://evolu.dev/docs/api-reference/common/Task/type-aliases/Task) that completes first.

Like
[Promise.race](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race),
the first Task to complete (whether success or failure) wins. All other Tasks
are aborted. Use [any](https://evolu.dev/docs/api-reference/common/Task/functions/any) if you need the first Task to succeed instead.

Requires a non-empty array — racing zero Tasks has no meaningful result
(there's no "first to complete" without participants). This is enforced at
compile time for non-empty tuple types. For other arrays, guard with
[isNonEmptyArray](https://evolu.dev/docs/api-reference/common/Array/functions/isNonEmptyArray):

```ts
if (isNonEmptyArray(tasks)) {
  await run(race(tasks));
}
```

### Example

```ts
const fast: Task<string> = () => ok("fast");
const slow: Task<string> = async (run) => {
  await run(sleep("10ms"));
  return ok("slow");
};

// First wins, others are aborted.
const result = await run(race([fast, slow])); // ok("fast")
```

Always runs with unlimited concurrency — a sequential race makes no sense
since the first Task would always "win".