Function tryp

  • Stores the result of the given Promise into a Result. If the promise fails, Err is returned. If the promise succeeds, Ok is returned.

    Parameters

    • promise: Promise<void>

    Returns Promise<Result<void, unknown>>

    Example

    const res = await tryp(fetch("/my/api")).mapErr((err) => apiError(err))
    if (res.isErr()) {
    return err(res.error)
    }
  • Type Parameters

    • T

    Parameters

    • promise: Promise<T>

    Returns Promise<Result<T, unknown>>