-
Notifications
You must be signed in to change notification settings - Fork 0
Class.ResultAsync
resultar / ResultAsync
The ResultAsync type.
This is a union of Result
and PromiseLike<Result>
• T
• E
-
PromiseLike
<Result
<T
,E
>>
new ResultAsync<
T
,E
>(res
):ResultAsync
<T
,E
>
• res: Promise
<Result
<T
, E
>>
ResultAsync
<T
, E
>
[asyncIterator]():
AsyncGenerator
<Result
<never
,E
>,T
,any
>
AsyncGenerator
<Result
<never
, E
>, T
, any
>
andThen<
R
>(f
):ResultAsync
<InferOkTypes
<R
>,E
|InferErrTypes
<R
>>
• R extends Result
<unknown
, unknown
>
• f
ResultAsync
<InferOkTypes
<R
>, E
| InferErrTypes
<R
>>
andThen<
R
>(f
):ResultAsync
<InferAsyncOkTypes
<R
>,E
|InferAsyncErrTypes
<R
>>
• R extends ResultAsync
<unknown
, unknown
>
• f
ResultAsync
<InferAsyncOkTypes
<R
>, E
| InferAsyncErrTypes
<R
>>
andThen<
U
,F
>(f
):ResultAsync
<U
,E
|F
>
• U
• F
• f
ResultAsync
<U
, E
| F
>
finally(
f
):DisposableResultAsync
<T
,E
>
• f
DisposableResultAsync
<T
, E
>
if(
fCondition
):object
• fCondition
object
true: <
X1
,Y1
>(fTrue
) =>object
• X1
• Y1
• fTrue
object
false: <
X2
,Y2
>(fFalse
) =>ResultAsync
<X1
|X2
,E
|Y1
|Y2
>
• X2
• Y2
• fFalse
ResultAsync
<X1
| X2
, E
| Y1
| Y2
>
log(
f
):ResultAsync
<T
,E
>
Performs a side effect for the Ok
variant of ResultAsync
.
This function can be used for control flow based on result values.
• f
The function to call if the result is Ok
ResultAsync
<T
, E
>
self
if the result is Err
, otherwise the result of f
map<
X
>(f
):ResultAsync
<X
,E
>
• X
• f
ResultAsync
<X
, E
>
mapErr<
U
>(f
):ResultAsync
<T
,U
>
• U
• f
ResultAsync
<T
, U
>
match<
A
,B
>(ok
,fnErr
):Promise
<A
|B
>
• A
• B = A
• ok
• fnErr
Promise
<A
| B
>
orElse<
R
>(f
):ResultAsync
<T
|InferOkTypes
<R
>,InferErrTypes
<R
>>
• R extends Result
<unknown
, unknown
>
• f
ResultAsync
<T
| InferOkTypes
<R
>, InferErrTypes
<R
>>
orElse<
R
>(f
):ResultAsync
<T
|InferAsyncOkTypes
<R
>,InferAsyncErrTypes
<R
>>
• R extends ResultAsync
<unknown
, unknown
>
• f
ResultAsync
<T
| InferAsyncOkTypes
<R
>, InferAsyncErrTypes
<R
>>
orElse<
U
,A
>(f
):ResultAsync
<T
|U
,A
>
• U
• A
• f
ResultAsync
<T
| U
, A
>
safeUnwrap():
AsyncGenerator
<Result
<never
,E
>,T
,any
>
AsyncGenerator
<Result
<never
, E
>, T
, any
>
will be removed in 2.0.0.
You can use safeTry
without this method.
safeTry(async function* () {
const okValue = yield* yourResult
})
Emulates Rust's ?
operator in safeTry
's body. See also safeTry
.
tap(
f
):ResultAsync
<T
,E
>
Performs a side effect for the Ok
variant of ResultAsync
.
This function can be used for control flow based on result values.
• f
The function to call if the result is Ok
ResultAsync
<T
, E
>
self
if the result is Err
, otherwise the result of f
tapError(
f
):ResultAsync
<T
,E
>
Performs a side effect for the Err
variant of ResultAsync
.
This function can be used for control flow based on result values.
• f
The function to call if the result is Err
ResultAsync
<T
, E
>
self
if the result is Ok
, otherwise the result of f
then<
A
,B
>(successCallback
?,failureCallback
?):PromiseLike
<A
|B
>
Attaches callbacks for the resolution and/or rejection of the Promise.
• A
• B
• successCallback?
• failureCallback?
PromiseLike
<A
| B
>
A Promise for the completion of which ever callback is executed.
PromiseLike.then
unwrapOr<
A
>(t
):Promise
<T
|A
>
• A
• t: A
Promise
<T
| A
>
unwrapOrThrow():
Promise
<T
>
Promise
<T
>
static
combine<T
>(asyncResultList
):CombineResultAsyncs
<T
>
• T extends readonly [ResultAsync
<unknown
, unknown
>, ResultAsync
<unknown
, unknown
>]
• asyncResultList: T
CombineResultAsyncs
<T
>
static
combine<T
>(asyncResultList
):CombineResultAsyncs
<T
>
• T extends readonly ResultAsync
<unknown
, unknown
>[]
• asyncResultList: T
CombineResultAsyncs
<T
>
static
combineWithAllErrors<T
>(asyncResultList
):CombineResultsWithAllErrorsArrayAsync
<T
>
• T extends readonly [ResultAsync
<unknown
, unknown
>, ResultAsync
<unknown
, unknown
>]
• asyncResultList: T
CombineResultsWithAllErrorsArrayAsync
<T
>
static
combineWithAllErrors<T
>(asyncResultList
):CombineResultsWithAllErrorsArrayAsync
<T
>
• T extends readonly ResultAsync
<unknown
, unknown
>[]
• asyncResultList: T
CombineResultsWithAllErrorsArrayAsync
<T
>
static
errAsync<T
,E
>(error
):ResultAsync
<T
,E
>
Returns a ResultAsync instance that is immediately resolved with a Result.err(error).
• T = never
• E = unknown
• error: E
The error to be wrapped in a Result.err.
ResultAsync
<T
, E
>
A ResultAsync instance with the given error and value type T.
static
fromPromise<T
,E
>(promise
,errorFn
):ResultAsync
<T
,E
>
Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error) based on the provided promise.
• T
• E
• promise: PromiseLike
<T
>
The promise to be wrapped in a ResultAsync.
• errorFn
A function that transforms the error from the promise into the error type E.
ResultAsync
<T
, E
>
A ResultAsync instance with the given promise and error type E.
static
fromSafePromise<T
,E
>(promise
):ResultAsync
<T
,E
>
Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error) based on the provided promise.
• T
• E = never
• promise: PromiseLike
<T
>
The promise to be wrapped in a ResultAsync.
ResultAsync
<T
, E
>
A ResultAsync instance with the given promise and error type E.
static
fromThrowable<A
,T
,E
>(fn
,errorFn
?): (...args
) =>ResultAsync
<T
,E
>
Wraps a async function with a try catch, creating a new function with the same
arguments but returning Ok
if successful, Err
if the function throws
• A extends readonly any
[]
• T
• E
• fn
function to wrap with ok on success or err on failure
• errorFn?
when an error is thrown, this will wrap the error result if provided
Function
a new function that returns a ResultAsync
• ...args: A
ResultAsync
<T
, E
>
static
okAsync<T
,E
>(value
):ResultAsync
<T
,E
>
Returns a ResultAsync instance that is immediately resolved with a Result.ok(value).
• T
• E = never
• value: T
The value to be wrapped in a Result.ok.
ResultAsync
<T
, E
>
A ResultAsync instance with the given value and error type E.
static
unitAsync<E
>():ResultAsync
<undefined
,E
>
Returns a ResultAsync that is immediately resolved with a Result.ok(undefined) value.
• E = never
ResultAsync
<undefined
, E
>
A ResultAsync instance with undefined as the value type and E as the error type.