diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-10-17 04:29:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-17 16:59:16 +0530 |
commit | 4c9dd33e27d31a0f6f8f26e043fbfbefa84db0f2 (patch) | |
tree | 43073429e2f8ca3d3bef2aa3bc0378ebf016a118 /ext/web/02_timers.js | |
parent | e41af14b2a5e7643e4d4e882b20a828ef0104757 (diff) |
perf(ext/web): optimize timer cancellation (#16316)
Towards #16315
It created a bunch of Error objects and rejected the promise. This patch
changes `op_sleep` to resolve with `true` if it was cancelled.
Diffstat (limited to 'ext/web/02_timers.js')
-rw-r--r-- | ext/web/02_timers.js | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/ext/web/02_timers.js b/ext/web/02_timers.js index 7c0bc1e3a..0fc808796 100644 --- a/ext/web/02_timers.js +++ b/ext/web/02_timers.js @@ -18,7 +18,6 @@ // deno-lint-ignore camelcase NumberPOSITIVE_INFINITY, PromisePrototypeThen, - ObjectPrototypeIsPrototypeOf, SafeArrayIterator, SymbolFor, TypeError, @@ -245,7 +244,12 @@ // 1. PromisePrototypeThen( sleepPromise, - () => { + (cancelled) => { + if (!cancelled) { + // The timer was cancelled. + removeFromScheduledTimers(timerObject); + return; + } // 2. Wait until any invocations of this algorithm that had the same // global and orderingIdentifier, that started before this one, and // whose milliseconds is equal to or less than this one's, have @@ -278,14 +282,6 @@ currentEntry = currentEntry.next; } }, - (err) => { - if (ObjectPrototypeIsPrototypeOf(core.InterruptedPrototype, err)) { - // The timer was cancelled. - removeFromScheduledTimers(timerObject); - } else { - throw err; - } - }, ); } |