Function tryOrElse

Produce a Task<T, E> from a Promise<T> and a function to transform an unknown error to E.

To leave any error as unknown, use the overload which accepts only the promise.

  • Produce a Task<T, E> from a Promise<T> and a function to transform an unknown error to E.

    To leave any error as unknown, use the overload which accepts only the promise.

    Type Parameters

    • T
    • E

    Parameters

    • promise: Promise<T>

      The promise from which to create the Task.

    • onRejection: (reason: unknown) => E

      A function to transform an unknown rejection reason into a known E.

    Returns Task<T, E>

    This will be removed at 9.0. Switch to the module-level function safelyTryOrElse, which accepts a callback instead.