1 2 3 4 5 6 7 8 9 |
x1 x5 x5 x20 x5 x5 x5 x5 |
/** Returns the current state of a promise. */
export async function state(promise: Promise<unknown>): Promise<"pending" | "fulfilled" | "rejected"> {
const check = new Promise<void>((resolve) => setTimeout(resolve, 0))
try {
return await Promise.race([promise.then((_) => "fulfilled" as const).catch((_) => "rejected" as const), check.then((_) => "pending" as const)])
} finally {
await check
}
}
|