Function asyncResult

  • const successfulResult = await asyncResult(Promise.resolve('some value')).map(value => value + ', another value');
    successfulResult.orNull(); // produces: "some value, another value"
    successfulResult.failureOrElse('definitely this'); // produces: "definitely this"
    const failureResult = await asyncResult(Promise.reject('some failure')).mapErr(value => value + ', another failure');
    failureResult.orNull(); // produces: null
    failureResult.failureOrElse('Not this'); // produces: "some failure, another failure"

    Type Parameters

    • S
    • F

    Parameters

    • promise: Promise<S>

    Returns Async<S, F>