Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit f5abe1c

Browse files
committed
Always replace AbortSignal.timeout
`AbortSignal.timeout` was added in Node 17.3.0. However, the Workers implementation allows `timeout(undefined)`, but Node's doesn't.
1 parent 26c3158 commit f5abe1c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/core/src/standards/timers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ export const AbortSignal =
3737
globalThis.AbortSignal ??
3838
Object.getPrototypeOf(new AbortController().signal).constructor;
3939

40-
// Polyfill `AbortSignal.timeout` as described here:
40+
// Replace `AbortSignal.timeout` as described here:
4141
// https://community.cloudflare.com/t/2021-12-10-workers-runtime-release-notes/334982
42-
// @ts-expect-error `timeout` isn't included in Node.js yet
43-
AbortSignal.timeout ??= function (ms?: number) {
42+
// @ts-expect-error `timeout` was added in Node 17.3.0
43+
AbortSignal.timeout = function (ms?: number) {
44+
// Confusingly, `timeout` allows `timeout(undefined)`, but not `timeout()`
4445
if (arguments.length === 0) {
4546
throw new TypeError(
4647
"Failed to execute 'timeout' on 'AbortSignal': parameter 1 is not of type 'integer'."
@@ -57,6 +58,7 @@ export interface SchedulerWaitOptions {
5758

5859
export class Scheduler {
5960
wait(ms?: number, options?: SchedulerWaitOptions): Promise<void> {
61+
// Confusingly, `wait` allows `wait(undefined)`, but not `wait()`
6062
if (arguments.length === 0) {
6163
throw new TypeError(
6264
"Failed to execute 'wait' on 'Scheduler': parameter 1 is not of type 'integer'."

packages/core/test/standards/timers.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ test("AbortSignal.timeout: requires numeric timeout", (t) => {
124124
test("AbortSignal.timeout: included on constructor obtained via AbortController#signal prototype", (t) => {
125125
const controller = new AbortController();
126126
const constructor = Object.getPrototypeOf(controller.signal).constructor;
127-
// @ts-expect-error `timeout` isn't included in Node.js yet
127+
// @ts-expect-error `timeout` was added in Node 17.3.0
128128
t.is(constructor.timeout, AbortSignal.timeout);
129129
});
130130

0 commit comments

Comments
 (0)