plainfp - v0.1.0
    Preparing search index...

    Function fromAsync

    • Invoke an async thunk and convert its resolution or rejection into a ResultAsync. Synchronous throws from fn itself are also captured.

      Type Parameters

      • T
      • E

      Parameters

      • fn: () => Promise<T>
      • onError: (cause: unknown) => E

      Returns ResultAsyncType<T, E>

      const chargeCard = (order: Order) =>
      fromAsync(
      () => paymentsApi.charge(order.total, order.card),
      (cause) => ({ code: "CHARGE_FAILED", cause }),
      )