Runs an async function and returns a Result. If the function succeeds, the Ok is returned. If the function fails, the Err is returned.
The type of the value.
The type of the error.
The async function to be run.
A Promise that resolves to a Result that is the result of running the given async function.
const result = await Result.runAsync(async () => { if (Math.random() > 0.5) { return 'Success'; } else { throw new Error('Failure'); }});if (result.isOk()) { console.log(result.unwrap()); // 'Success'} else { console.error(result.unwrapError()); // Error: 'Failure'} Copy
const result = await Result.runAsync(async () => { if (Math.random() > 0.5) { return 'Success'; } else { throw new Error('Failure'); }});if (result.isOk()) { console.log(result.unwrap()); // 'Success'} else { console.error(result.unwrapError()); // Error: 'Failure'}
Runs an async function and returns a Result. If the function succeeds, the Ok is returned. If the function fails, the Err is returned.