type alias MaybeAsync

A type that accepts either a Result or AsyncResult with the same T and E types.

This allows functions to return either synchronous or asynchronous results interchangeably, making it easy to optimize or refactor without changing signatures.

Examples

Example 1

function getUser(id: string): MaybeAsync<User, NotFoundError> {
  if (cache.has(id)) {
    return Result.ok(cache.get(id)); // Synchronous return
  }
  return AsyncResult.try(async () => {
    return await fetchUser(id); // Asynchronous return
  });
}

Type Parameters

E extends BaseError

Definition

Result<T, E> | AsyncResult<T, E> | Promise<Result<T, E>>

Usage

import { type MaybeAsync } from "result/mod.ts";