From bbc43d7ec141c35b65da1de0e376def72220e61b Mon Sep 17 00:00:00 2001 From: arteeh Date: Tue, 20 Oct 2026 07:03:53 +0000 Subject: [PATCH] refactor(scripts): create fetch deadline with Promise.withResolvers Replace the mutable reject closure with the native promise resolver API while preserving the abort reason and shared fetch/body deadline. Hive-Run: hivecommons/docs#396 Hive-Plan: replace-mutable-deadline-closure Hive-Spec: hivecommons/docs#396 Signed-off-by: arteeh --- scripts/fetch-with-timeout.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 {