Wraps an async function that may throw into a function that returns a ResultAsync.
The async function to wrap that may throw an error
A label to identify the error when the function throws
A function that returns a ResultAsync
const safeFetch = fromAsyncThrowable(fetch, 'FETCH_ERROR');const success = await safeFetch('https://api.example.com/data'); // [null, data]const fail = await safeFetch('invalid-url'); // [Err<'FETCH_ERROR'>, undefined] Copy
const safeFetch = fromAsyncThrowable(fetch, 'FETCH_ERROR');const success = await safeFetch('https://api.example.com/data'); // [null, data]const fail = await safeFetch('invalid-url'); // [Err<'FETCH_ERROR'>, undefined]
Wraps an async function that may throw into a function that returns a ResultAsync.