method AsyncResult.prototype.take
AsyncResult.prototype.take(): Promise<T | Result<never, E>>

Extracts the value from Ok or returns the Err for early returns.

This is the async version of Result.take(). It returns a Promise that resolves to either the unwrapped value T or an Err Result.

Examples

Example 1

async function processUser(id: string): Promise<Result<string, AppError>> {
  const user = await fetchUser(id).take();
  if (isErr(user)) return user;

  const perms = await fetchPermissions(user.id).take();
  if (isErr(perms)) return perms;

  return Result.ok(perms.join(", "));
}

Return Type

Promise<T | Result<never, E>>

Promise of the unwrapped value or Err Result

Usage

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