Interface Async<SUCCESS, FAILURE>

The AsyncResult is something that Damien LeBfailureigaud has introduced me to. I had the chance to work with him on a project that inspired me to write this lib. Together we collaborated on React Redux Starter to aid us in developing future projects with clients.

The type allows you to work with a promise in the same way you would work with a Result, with some extra helpers.

A factory for creating AsyncResult's

interface Async<SUCCESS, FAILURE> {
    either: (<NS, NF>(onSuccess, onFailure) => Async<NS, NF>);
    inspect: (() => Promise<string>);
    mBind: (<U>(f) => Async<U, FAILURE>);
    map: (<U>(f) => Async<U, FAILURE>);
    onComplete: ((f) => Async<SUCCESS, FAILURE>);
    onFailure: ((f) => Async<SUCCESS, FAILURE>);
    onPending: ((f) => Async<SUCCESS, FAILURE>);
    onSuccess: ((f) => Async<SUCCESS, FAILURE>);
    or: (<U>(f) => Async<SUCCESS, U>);
    orElse: ((fallback) => Promise<SUCCESS>);
    orNull: (() => Promise<null | SUCCESS>);
    value: Promise<Result<SUCCESS, FAILURE>>;
}

Type Parameters

  • SUCCESS
  • FAILURE

Properties

either: (<NS, NF>(onSuccess, onFailure) => Async<NS, NF>)

Type declaration

inspect: (() => Promise<string>)

Type declaration

    • (): Promise<string>
    • Returns Promise<string>

mBind: (<U>(f) => Async<U, FAILURE>)

Type declaration

map: (<U>(f) => Async<U, FAILURE>)

Type declaration

onComplete: ((f) => Async<SUCCESS, FAILURE>)

Type declaration

onFailure: ((f) => Async<SUCCESS, FAILURE>)

Type declaration

onPending: ((f) => Async<SUCCESS, FAILURE>)

onPending: A function that notifies the consuming function of the pending state.

Upon invocation it will pass true to the consumer. Once the call has finished it will pass false to the consumer.

Type declaration

Remarks

The provided consumer gets called twice.

onSuccess: ((f) => Async<SUCCESS, FAILURE>)

Type declaration

or: (<U>(f) => Async<SUCCESS, U>)

Type declaration

orElse: ((fallback) => Promise<SUCCESS>)

Type declaration

orNull: (() => Promise<null | SUCCESS>)

Type declaration

value: Promise<Result<SUCCESS, FAILURE>>