@usersatoshi/results
    Preparing search index...

    Function safeCall

    • Safely call a value, function, or promise and capture exceptions as Result.

      Overloads:

      • safeCall(promise, onErr) -> Promise<Result<T, E>>
      • safeCall(fn, onErr) -> Result<T, E> or Promise<Result<T, E>> (if fn returns a promise)

      onErr is used to map thrown or rejected values into a typed error E.

      Type Parameters

      • T
      • E extends { kind: number }

      Parameters

      • fn: Promise<T>

        a value, sync function, async function, or a promise

      • onErr: (error: unknown) => E

        maps thrown/rejected values into E

      Returns Promise<Ok<T> | Err<E>>

      a Result<T, E> or Promise<Result<T, E>> depending on the input

    • Safely call a value, function, or promise and capture exceptions as Result.

      Overloads:

      • safeCall(promise, onErr) -> Promise<Result<T, E>>
      • safeCall(fn, onErr) -> Result<T, E> or Promise<Result<T, E>> (if fn returns a promise)

      onErr is used to map thrown or rejected values into a typed error E.

      Type Parameters

      • T
      • E extends { kind: number }

      Parameters

      • fn: () => T

        a value, sync function, async function, or a promise

      • onErr: (error: unknown) => E

        maps thrown/rejected values into E

      Returns Ok<T> | Err<E>

      a Result<T, E> or Promise<Result<T, E>> depending on the input

    • Safely call a value, function, or promise and capture exceptions as Result.

      Overloads:

      • safeCall(promise, onErr) -> Promise<Result<T, E>>
      • safeCall(fn, onErr) -> Result<T, E> or Promise<Result<T, E>> (if fn returns a promise)

      onErr is used to map thrown or rejected values into a typed error E.

      Type Parameters

      • T
      • E extends { kind: number }

      Parameters

      • fn: () => Promise<T>

        a value, sync function, async function, or a promise

      • onErr: (error: unknown) => E

        maps thrown/rejected values into E

      Returns Promise<Ok<T> | Err<E>>

      a Result<T, E> or Promise<Result<T, E>> depending on the input