Skip to content

Commit

Permalink
fix regression when timeout is marginal
Browse files Browse the repository at this point in the history
  • Loading branch information
MDSLKTR committed May 8, 2023
1 parent ff3b111 commit 9ad0fea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/network/requestQueue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,12 @@ module.exports = class RequestQueue extends EventEmitter {
// will be fine, and potentially fix up a new timeout if needed at that time.
// Note that if we're merely "overloaded" by having too many inflight requests
// we will anyways check the queue when one of them gets fulfilled.
let scheduleAt = this.throttledUntil - Date.now()
if (!this.throttleCheckTimeoutId) {
if (this.pending.length > 0) {
scheduleAt = scheduleAt > 0 ? scheduleAt : CHECK_PENDING_REQUESTS_INTERVAL
}
const timeUntilUnthrottled = this.throttledUntil - Date.now()
if (timeUntilUnthrottled >= 0 && !this.throttleCheckTimeoutId) {
this.throttleCheckTimeoutId = setTimeout(() => {
this.throttleCheckTimeoutId = null
this.checkPendingRequests()
}, scheduleAt)
}, Math.max(timeUntilUnthrottled, CHECK_PENDING_REQUESTS_INTERVAL))
}
}
}
4 changes: 2 additions & 2 deletions src/network/requestQueue/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ describe('Network > RequestQueue', () => {
const before = Date.now()
const clientSideThrottleTime = 1
requestQueue.maybeThrottle(clientSideThrottleTime)
// Sleep until the marginal delay is passed before calling scheduleCheckPendingRequests()
await sleep(clientSideThrottleTime)

requestQueue.throttledUntil = Date.now() + clientSideThrottleTime
requestQueue.scheduleCheckPendingRequests()

const sentAt = await sendDone
Expand Down

0 comments on commit 9ad0fea

Please sign in to comment.