Overview
ThefromPromise and fromSafePromise static methods convert Promises into ResultAsync instances.
Signatures
fromPromise
PromiseLike<T>
required
A Promise that may resolve or reject
(e: unknown) => E
required
Function to map the rejection reason to a known error type
fromSafePromise
PromiseLike<T>
required
A Promise that will never reject
Usage
Basic fromPromise usage
Type-safe error mapping
Chaining after fromPromise
fromSafePromise usage
Rate limiting with safe promises
When to use each
Use fromPromise when:
- Working with third-party APIs that may reject
- Fetching from network (fetch, axios)
- File I/O operations
- Database queries
- Any Promise that might reject
Use fromSafePromise when:
- Creating delays with setTimeout
- Wrapping synchronous operations in Promises
- Working with Promise.resolve()
- You guarantee the Promise never rejects
Comparison
Top-level exports
These methods are also available as standalone functions:Related
from-throwable
Wrap functions that might throw
Async Operations Guide
Working with async operations