@book000/pixivts - v0.61.1
    Preparing search index...

    Class ResultAsync<T, E>

    A PromiseLike<Result<T, E>> that is directly await-able and supports chainable map / mapErr / andThen operators.

    const result = await ResultAsync.fromPromise(fetch('/api'), networkError)
    .andThen((res) =>
    ResultAsync.fromPromise(res.json() as Promise<unknown>, networkError)
    )

    Type Parameters

    • T
    • E

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Methods

    • Pattern-matches on success / failure.

      Type Parameters

      • U

      Parameters

      • onOk: (value: T) => U | Promise<U>

        Called with the success value

      • onErr: (error: E) => U | Promise<U>

        Called with the error value

      Returns Promise<U>

      A Promise<U>

    • Attaches callbacks for the resolution and/or rejection of the Promise.

      Type Parameters

      Parameters

      • Optionalonfulfilled: ((value: Result<T, E>) => TResult1 | PromiseLike<TResult1>) | null

        The callback to execute when the Promise is resolved.

      • Optionalonrejected: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null

        The callback to execute when the Promise is rejected.

      Returns PromiseLike<TResult1 | TResult2>

      A Promise for the completion of which ever callback is executed.

    • Returns the success value, or fallback if the result is Err.

      Parameters

      • fallback: T

        The fallback value

      Returns Promise<T>

    • Wraps a Promise<T> into a ResultAsync<T, E>.

      If the promise rejects, onError maps the rejection reason to E.

      Type Parameters

      • T
      • E

      Parameters

      • promise: Promise<T>

        The promise to wrap

      • onError: (reason: unknown) => E

        Error mapper

      Returns ResultAsync<T, E>