fromSafePromise()
constfromSafePromise: <T,E>(promise) =>ResultAsync<T,E> =ResultAsync.fromSafePromise
Convenience export for ResultAsync.fromSafePromise.
Creates a ResultAsync from a Promise that is guaranteed to resolve successfully. This method assumes the Promise will never reject, so use with caution.
Type Parameters
T: T
The type of the value in the Promise
E: E = never
The type of the error (defaults to never)
Parameters
promise: Promise<T>
Promise that will resolve to a value
Returns: ResultAsync<T, E>
A new ResultAsync that will resolve to Ok(value)
Example
const promise = Promise.resolve(42);
const result = ResultAsync.fromSafePromise(promise);
const resolved = await result;
// resolved is Ok(42)
Since
2.0.0
Example
import { fromSafePromise } from './result-async';
const result = fromSafePromise(Promise.resolve(42));