Const
Runs multiple FPromises in parallel and returns an array of results. Similar to Promise.all, this will reject if any of the promises reject.
Like Promise.allSettled, returns results of all promises whether they succeed or fail. This will always resolve, never reject.
Like Promise.any, returns the first promise to fulfill. This will only reject if all promises reject.
Creates an FPromise from a regular Promise.
Creates an FPromise from an Either. If the Either is a Right, the FPromise resolves with the Right value. If the Either is a Left, the FPromise rejects with the Left value.
Like Promise.race, returns the first promise to settle (either resolve or reject).
Creates an FPromise that rejects with the provided reason.
Creates an FPromise that resolves to the provided value.
Retries an operation with exponential backoff. This is useful for operations that may fail temporarily, such as network requests.
const operation = () => {
if (Math.random() > 0.8) {
return FPromise.resolve("Success!")
}
return FPromise.reject<string, Error>(new Error("Temporary failure"))
}
const result = await FPromise.retryWithBackoff(operation, {
maxRetries: 3,
baseDelay: 100,
shouldRetry: (error) => error.message === "Temporary failure"
}).toPromise()
Static utility methods for FPromise using the Companion pattern. These methods provide factory functions and utilities for working with FPromises.