Wrap an async function fn so its returned Promise resolves with a Result instead of rejecting.
fn
Promise
Result
const fetchJson = resultifyAsync(async (url: string) => { const response = await fetch(url); return response.json();});await fetchJson('https://example.com'); // { ok: ..., isOk: true, isError: false } Copy
const fetchJson = resultifyAsync(async (url: string) => { const response = await fetch(url); return response.json();});await fetchJson('https://example.com'); // { ok: ..., isOk: true, isError: false }
Wrap an async function
fnso its returnedPromiseresolves with aResultinstead of rejecting.