• English
  • Type Alias: ResultAsync<T, E>

    ResultAsync<T, E> = Promise<Result<T, E>>

    An asynchronous variant of Result, wrapped in a Promise.

    Type Parameters

    T

    T

    The type of the Success value.

    E

    E

    The type of the Failure value.

    Example

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const fetchData: () => Result.ResultAsync<string, Error>
    fetchData
    = async ():
    import Result
    Result
    .
    type ResultAsync<T, E> = Promise<Result.Result<T, E>>

    An asynchronous variant of Result , wrapped in a Promise.

    @typeParamT - The type of the Success value.@typeParamE - The type of the Failure value.@example
    import { Result } from '@praha/byethrow';
    
    const fetchData = async (): Result.ResultAsync<string, Error> => {
      try {
        const data = await fetch('...');
        return { type: 'Success', value: await data.text() };
      } catch (err) {
        return { type: 'Failure', error: err as Error };
      }
    };
    @categoryCore Types
    ResultAsync
    <string, Error> => {
    try { const
    const data: Response
    data
    = await
    function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>
    fetch
    ('...');
    return {
    type: "Success"
    type
    : 'Success',
    value: string
    value
    : await
    const data: Response
    data
    .
    Body.text(): Promise<string>
    text
    () };
    } catch (
    function (local var) err: unknown
    err
    ) {
    return {
    type: "Failure"
    type
    : 'Failure',
    error: Error
    error
    :
    function (local var) err: unknown
    err
    as Error };
    } };