Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/effection/lib/mod.ts>race

Structured concurrency and effects for JavaScript
Latest
function race
Re-export
import { race } from "https://deno.land/x/effection@4.0.0-alpha.1/lib/mod.ts";

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 Operation<unknown>

Parameters

operations: readonly T[]

a list of operations to race against each other

Returns

the value of the fastest operation