Skip to main content
Module

x/fun/promise.ts>race

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function race
import { race } from "https://deno.land/x/fun@v2.0.0/promise.ts";

An alias for Promise.race. Note that Promise.race leaks async operations in most runtimes. This means that the slower promise does not stop when the faster promise resolves/rejects. In effect Promise.race does not handle cancellation.

Examples

Example 1

import { wait, map, race, wrap } from "./promise.ts";
import { pipe } from "./fn.ts";

const one = pipe(wait(200), map(() => "one"));
const two = pipe(wait(300), map(() => "two"));

// After 200 milliseconds resolves from one
const result = await race(one, two); // "one"

Returns

Promise<Awaited<T[keyof T]>>