Effection Logo

function race

thefrontside/effection

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.

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

import { main, race, fetch } from 'effection';

await main(function*() {
 let fastest = yield* race([fetch('http://google.com'), fetch('http://bing.com')]);
 // ...
});

Type Parameters

T extends https://effection-www-7a79x8qmc0zv.deno.dev/api/v3/Operation&lt;unknown>

Parameters

operations: readonly T[]

a list of operations to race against each other

Return Type

https://effection-www-7a79x8qmc0zv.deno.dev/api/v3/Operation&lt;https://effection-www-7a79x8qmc0zv.deno.dev/api/v3/Yielded&lt;T>>

the value of the fastest operation