Function fromPromise

  • Produce a Task<T, unknown> from a Promise.

    To handle the error case and produce a Task<T, E> instead, use the overload the overload which accepts an onRejection handler instead.

    Important

    This does not (and by definition cannot) handle errors that happen during construction of the Promise, because those happen before this is called. See safelyTry, safelyTryOr, or safelyTryOrElse for alternatives which accept a callback for constructing a promise and can therefore handle errors thrown in the call.

    Type Parameters

    • T

      The type the Promise would resolve to, and thus that the Task will also resolve to if the Promise resolves.

    Parameters

    • promise: Promise<T>

      The promise from which to create the Task.

    Returns Task<T, unknown>

  • Produce a Task<T, E> from a Promise, using a .

    To absorb all errors/rejections as unknown, use the overload without an onRejection handler instead.

    Important

    This does not (and by definition cannot) handle errors that happen during construction of the Promise, because those happen before this is called. See safelyTry, safelyTryOr, or safelyTryOrElse for alternatives which accept a callback for constructing a promise and can therefore handle errors thrown in the call.

    Type Parameters

    • T

      The type the Promise would resolve to, and thus that the Task will also resolve to if the Promise resolves.

    • E

      The type of a rejected Task if the promise rejects.

    Parameters

    • promise: Promise<T>

      The promise from which to create the Task.

    • onRejection: (reason: unknown) => E

      Transform errors from unknown to a known error type.

    Returns Task<T, E>