Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
msutkowski committed Jan 22, 2022
1 parent 226b6a6 commit ecdbb0e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/toolkit/src/query/core/buildMiddleware/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ export const build: SubMiddlewareBuilder = ({
}

const lowestPollingInterval = findLowestPollingInterval(subscriptions)
const currentPoll = currentPolls[queryCacheKey]

if (!Number.isFinite(lowestPollingInterval)) {
cleanupPollForKey(queryCacheKey)
return
}

const currentPoll = currentPolls[queryCacheKey]
const nextPollTimestamp = Date.now() + lowestPollingInterval

if (!currentPoll || nextPollTimestamp < currentPoll.nextPollTimestamp) {
Expand All @@ -119,7 +119,9 @@ export const build: SubMiddlewareBuilder = ({

function cleanupPollForKey(key: string) {
const existingPoll = currentPolls[key]
existingPoll?.timeout && clearTimeout(existingPoll.timeout)
if (existingPoll?.timeout) {
clearTimeout(existingPoll.timeout)
}
delete currentPolls[key]
}

Expand Down

0 comments on commit ecdbb0e

Please sign in to comment.