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));