diff --git a/src/network/requestQueue/index.js b/src/network/requestQueue/index.js index eee14d66c..8556667a4 100644 --- a/src/network/requestQueue/index.js +++ b/src/network/requestQueue/index.js @@ -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)) } } } diff --git a/src/network/requestQueue/index.spec.js b/src/network/requestQueue/index.spec.js index 238fbf310..b6e924183 100644 --- a/src/network/requestQueue/index.spec.js +++ b/src/network/requestQueue/index.spec.js @@ -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