The promise to handle.
An object with a single method called case
.
Optional
pending?: (() => void)Optional
rejected?: ((error) => void)Optional
resolved?: ((value) => void)const promise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("Hello, world!");
}, 1000);
});
const fromPromiseResult = fromPromise(promise);
await fromPromiseResult.case({
resolved: (value) => {
console.log("Resolved:", value); // Resolved: Hello, world!
},
rejected: () => {
console.log("Rejected");
},
pending: () => {
console.log("Pending"); // Pending
},
});
Creates an object that provides a way to handle the result of a Promise. The object has a single method called
case
which takes an object with three optional methods:resolved
,rejected
, andpending
. The appropriate method will be called based on the state of the promise.