Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions async/deadline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export interface DeadlineOptions {
* custom `reason` before resolving or timing out.
* @typeParam T The type of the provided and returned promise.
* @param p The promise to make rejectable.
* @param ms Duration in milliseconds for when the promise should time out.
* @param ms Duration in milliseconds for when the promise should time out. If
* greater than `Number.MAX_SAFE_INTEGER`, the deadline will never expire.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* @param options Additional options.
* @returns A promise that will reject if the provided duration runs out before resolving.
*
Expand All @@ -43,7 +44,8 @@ export async function deadline<T>(
ms: number,
options: DeadlineOptions = {},
): Promise<T> {
const signals = [AbortSignal.timeout(ms)];
const signals: AbortSignal[] = [];
if (ms < Number.MAX_SAFE_INTEGER) signals.push(AbortSignal.timeout(ms));
if (options.signal) signals.push(options.signal);
return await abortable(p, AbortSignal.any(signals));
}
5 changes: 5 additions & 0 deletions async/deadline_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,8 @@ Deno.test("deadline() handles already aborted signal", async () => {
assertEquals(error.name, "AbortError");
controller.abort();
});

Deno.test("deadline() supports numbers greater than Number.MAX_SAFE_INTEGER", async () => {
const promise = await deadline(Promise.resolve("Hello"), Infinity);
assertEquals(promise, "Hello");
});
Loading