ResultAsync<
T,E> =Promise<Result<T,E>>
Defined in: result.ts:92
An asynchronous variant of Result, wrapped in a Promise.
T
The type of the Success value.
E
The type of the Failure value.
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.
ResultAsync <string, Error> => {
try {
const const data: Response data = await function fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> (+1 overload) 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 };
}
};