diff --git a/scripts/fetch-with-timeout.ts b/scripts/fetch-with-timeout.ts index 88395f4..7121a77 100644 --- a/scripts/fetch-with-timeout.ts +++ b/scripts/fetch-with-timeout.ts @@ -34,17 +34,14 @@ async function fetchWithDeadline( ): Promise> { const controller = new AbortController(); let timedOut = false; - let expire: () => void = () => {}; // Raced against both the fetch and the body read: the body stream of a // fetch stub may ignore the abort signal, and the deadline must hold anyway. - const deadline = new Promise((_resolve, reject) => { - expire = () => reject(controller.signal.reason); - }); + const { promise: deadline, reject: expire } = Promise.withResolvers(); deadline.catch(() => {}); const timer = setTimeout(() => { timedOut = true; controller.abort(); - expire(); + expire(controller.signal.reason); }, timeoutMs); let response: Response | undefined; try {