Skip to content

Commit

Permalink
🔀 set 3 seconds max wait time for the idle callback based strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Mar 18, 2024
1 parent fa8f1d3 commit dc1370a
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/ricTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,26 @@ class RicTracker {
return
}

this.#idleCallbackId = requestIdleCallback((deadline) => {
this.#idleDeadline = deadline
this.#idleCallbackId = undefined

this.#deferred.resolve(deadline)

this.#deferred = withResolvers<IdleDeadline>()

this.start()
})
this.#idleCallbackId = requestIdleCallback(
(deadline) => {
this.#idleDeadline = deadline
this.#idleCallbackId = undefined

this.#deferred.resolve(deadline)

this.#deferred = withResolvers<IdleDeadline>()

this.start()
},
{
// wait 3 seconds max to call the next idle callback:
// - if the browser is actually busy for 3 seconds, we can at least call
// rarely and probably the `deadline` will have very little time left
// - previously Chromium had a bug where it wouldn't fire the idle
// callback. the timeout just in case some browser has such a problem.
timeout: 3000,
},
)
}

stop() {
Expand Down

0 comments on commit dc1370a

Please sign in to comment.