The type of the value that the promise resolves to.
The type of the error that may be rejected, defaults to Error.
A promise or promise-like object to await.
A promise that resolves to Ok<T> if successful, or Err<E> if rejected.
Executes a function and captures any thrown exception or rejection as an Err.
If the function succeeds, returns Ok with the result.
This overload accepts a function that may return a sync value or a Promise. It captures both synchronous exceptions (thrown before the Promise is created) and asynchronous rejections.
Similar to Promise.try, you can pass arguments to the function.
The type of the value returned or resolved by the function.
The type of the error that may be thrown or rejected, defaults to Error.
The types of the arguments to pass to the function.
A promise that resolves to Ok<T> if successful, or Err<E> if thrown or rejected.
// Function can return sync or async value (like Promise.try)
const result = await tryAsyncResult((id) => {
if (cache.has(id)) return cache.get(id); // sync return
return fetchFromServer(id); // async return
}, 'user-123');
Executes an async operation and captures any rejection as an
Err. If the operation succeeds, returnsOkwith the resolved value.This overload accepts a Promise or PromiseLike object directly. Use this to convert Promise-based error handling to Result-based handling.