From 24465d155378c4b617a658a27385f1da2e381d90 Mon Sep 17 00:00:00 2001 From: clover caruso Date: Tue, 3 Feb 2026 03:44:37 -0800 Subject: [PATCH] feat(lib/async): delay now works for long periods of time --- lib/async.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/async.ts b/lib/async.ts index e1f2eaf14d3bd48d4e8e7fff2cef01b74b750da8..dd7d69fb8b6a9ad612b131bda75045ffa35f3ceb 100644 --- a/lib/async.ts +++ b/lib/async.ts @@ -238,9 +238,17 @@ export function makeCancelable( /** wait `ms` milliseconds, then resolve. can be cancelled. */ export function delay(ms: number): Cancelable { let t: ts.Timer | null = null; + const maxTimer = 0x7FFFFFFF; return makeCancelable( - new Promise((resolve) => { - t = globalThis.setTimeout(() => (t = null, resolve()), ms); + new Promise(function tick(resolve) { + if (ms <= maxTimer) { + t = setTimeout(() => (t = null, resolve()), ms); + } else { + t = setTimeout(() => { + ms -= maxTimer; + tick(resolve); + }, maxTimer); + } }), () => { if (t != null) clearTimeout(t); -- 2.54.0