Skip to content

Function.fromThrowableAsync

GitHub Actions edited this page Mar 5, 2025 · 27 revisions

resultar / fromThrowableAsync

Function: fromThrowableAsync()

fromThrowableAsync<A, T, E>(fn, errorFn?): (...args) => ResultAsync<T, E>

Defined in: result-async.ts:473

Wraps a async function with a try catch, creating a new function with the same arguments but returning Ok if successful, Err if the function throws

Type Parameters

A extends readonly any[]

T

E

Parameters

fn

(...args) => Promise<T>

function to wrap with ok on success or err on failure

errorFn?

(err) => E

when an error is thrown, this will wrap the error result if provided

Returns

Function

a new function that returns a ResultAsync

Parameters

args

...A

Returns

ResultAsync<T, E>

Clone this wiki locally