Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/eitherway/lib/async/tasks.ts>all

Yet Another Option and Result Implementation - providing safe abstractions for fallible flows inspired by F# and Rust
Latest
function all
import { all } from "https://deno.land/x/eitherway@0.10.0/lib/async/tasks.ts";

Use this to collect all Ok<T> values from an Array<Task<T,E>> or Iterable<Task<T,E>> into an Task<T[],E>. Upon encountring the first Err<E> value, this value is returned.

This function also works on variadic tuples and preserves the individual types of the tuple members.

Examples

Example 1

import { Task, Tasks } from "./mod.ts";
import { Result } from "../core/result.ts";

const str = "thing" as string | TypeError;
const num = 5 as number | RangeError;
const bool = true as boolean | ReferenceError;

const tuple = [
  Task.of(Result(str)),
  Task.of(Result(num)),
  Task.of(Result(bool)),
] as const;

const res: Result<
  readonly [string, number, boolean],
  TypeError | RangeError | ReferenceError
> = await Tasks.all(tuple);

Type Parameters

P extends Readonly<ArrayLike<PromiseLike<Result<unknown, unknown>>>>

Parameters

tasks: Readonly<Iterable<PromiseLike<Result<T, E>>>>