deadline
import { deadline } from "jsr:@ende/async";function
async function deadline<T>(p: Promise<T>, ms: number, options: DeadlineOptions = [UNSUPPORTED]): Promise<T>Create a promise which will be rejected with DOMException when
a given delay is exceeded.
Note: Prefer to use AbortSignal.timeout instead for the APIs
that accept AbortSignal.
p: Promise<T>The promise to make rejectable.
ms: numberDuration in milliseconds for when the promise should time out. If greater than
Number.MAX_SAFE_INTEGER, the deadline will never expire.options: DeadlineOptions = [UNSUPPORTED]Additional options.
Returns
A promise that will reject if the provided duration runs out before resolving.
Example: Usage
import { deadline } from "@ende/async/deadline";
import { delay } from "@ende/async/delay";
const delayedPromise = delay(1_000);
// Below throws `DOMException` after 10 ms
const result = await deadline(delayedPromise, 10);