method AsyncResult.any
AsyncResult.any<T, E extends BaseError>(results: readonly (AsyncResult<T, E> | Promise<Result<T, E>>)[]): AsyncResult<T, E>

Returns the first Ok result from an array of AsyncResults.

If any Result is Ok, returns that Ok result. If all Results are Err, returns the last Err.

Examples

Example 1

const data = await AsyncResult.any([
  fetchFromPrimary(),
  fetchFromSecondary(),
  fetchFromBackup()
]).take();

if (Result.isErr(data)) {
  console.error("All sources failed");
} else {
  console.log(data); // First successful result
}

Type Parameters

The type of the Ok values

E extends BaseError

The type of the errors

Parameters

results: readonly (AsyncResult<T, E> | Promise<Result<T, E>>)[]

Array of AsyncResults or Promises to check

Return Type

AsyncResult with the first Ok, or the last Err

Usage

import { AsyncResult } from "result/mod.ts";