Skip to content

Commit

Permalink
🐛 frameTracker never stops running
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Feb 5, 2024
1 parent 476b29f commit 0df5084
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/frameTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,20 @@ class FrameTracker {
start(): void {
clearTimeout(this.#timeoutId)
this.#timeoutId = undefined
this.#loop()
}

requestStop(): void {
if (this.#timeoutId === undefined) {
this.#timeoutId = setTimeout(() => {
this.#timeoutId = undefined
cancelAnimationFrame(this.#requestAnimationId)
this.#requestAnimationId = undefined
}, 200)
}
}

#loop(): void {
if (this.#requestAnimationId === undefined) {
this.#requestAnimationId = requestAnimationFrame(() => {
this.#requestAnimationId = undefined
Expand All @@ -31,20 +44,10 @@ class FrameTracker {

this.#deferred = withResolvers()

this.start()
this.#loop()
})
}
}

requestStop(): void {
if (this.#timeoutId === undefined) {
this.#timeoutId = setTimeout(() => {
this.#timeoutId = undefined
cancelAnimationFrame(this.#requestAnimationId)
this.#requestAnimationId = undefined
}, 200)
}
}
}

const frameTracker = new FrameTracker()
Expand Down

0 comments on commit 0df5084

Please sign in to comment.