Converts an async function that may throw an error into a function that returns a ResultAsync.
The arguments of the function.
The return type of the function.
A string literal type for the error label.
The async function that may throw an error.
The error label to use if the function throws.
A new async function that wraps the original function and returns a ResultAsync.
const safeFetch = fromAsyncThrowable(fetch, 'fetch_error');const [error, response] = await safeFetch('https://api.example.com/data');if (error) { // Handle fetch error} else { // Use response} Copy
const safeFetch = fromAsyncThrowable(fetch, 'fetch_error');const [error, response] = await safeFetch('https://api.example.com/data');if (error) { // Handle fetch error} else { // Use response}
Converts an async function that may throw an error into a function that returns a ResultAsync.