# race

```ts
function* race<T extends Operation<unknown>>(operations: readonly T[]): Operation<Yielded<T>>
```

Race the given operations against each other and return the value of
whichever operation returns first. This has the same purpose as
[Promise.race](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race).

If an operation become errored first, then `race` will fail with this error.
After the first operation wins the race, all other operations will become
halted and therefore cannot throw any further errors.

### Examples
#### Example 1
```typescript
import { race, sleep, call } from "effection";

  let fastest = yield* race([
    call(function* () {
      yield* sleep(100);
      // this is halted as it loses the race
      return "slow";
    }),
    call(function* () {
      yield* sleep(10);
      return "fast";
    }),
  ]);

  console.log(fastest); // "fast"
```

---
### Type Parameters
T extends [Operation](https://frontside.com/effection/api/v4-next/Operation.md)&lt;unknown&gt;


### Parameters


**operations**: readonly T&lbrack;&rbrack;


a list of operations to race against each other
### Return Type


[Operation](https://frontside.com/effection/api/v4-next/Operation.md)&lt;[Yielded](https://frontside.com/effection/api/v4-next/Yielded.md)&lt;T&gt;&gt;


the value of the fastest operation

[View code](https://github.com/thefrontside/effection/tree/effection-v4.2.0/lib/race.ts#L41)
