Skip to main content

fromSafePromise()

const fromSafePromise: <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));