method AsyncResult.prototype.then
AsyncResult.prototype.then<TResult1 = Result<T, E>, TResult2 = never>(
onfulfilled?:
((value: Result<T, E>) => TResult1 | PromiseLike<TResult1>)
| null,
onrejected?:
((reason: unknown) => TResult2 | PromiseLike<TResult2>)
| null
): Promise<TResult1 | TResult2>

Implements PromiseLike to make AsyncResult awaitable.

Type Parameters

TResult1 = Result<T, E>

The type when fulfilled

TResult2 = never

The type when rejected

Parameters

optional
onfulfilled:
((value: Result<T, E>) => TResult1 | PromiseLike<TResult1>)
| null

Callback for when the promise is fulfilled

optional
onrejected:
((reason: unknown) => TResult2 | PromiseLike<TResult2>)
| null

Callback for when the promise is rejected

Return Type

Promise<TResult1 | TResult2>

A Promise of the result

Usage

import { AsyncResult } from "result/mod.ts";