Skip to content

Conversation

Richienb
Copy link
Collaborator

@Richienb
Copy link
Collaborator Author

// @sindresorhus

@Richienb Richienb marked this pull request as draft September 29, 2025 13:25
@Richienb Richienb marked this pull request as ready for review September 29, 2025 13:31
@sindresorhus
Copy link
Owner

Needs a test for when toggling infinite to finite mid-interval.

  • Finite to infinity while rate-limited. ensure additional tasks start immediately (after flag reset).
  • Infinity to finite with queued tasks. ensure throttling resumes and no more than intervalCap run until the next tick.

return this.#intervalCount;
}

set intervalCap(value: number) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the cap mid-interval must claer ratelimit state. When setting intervalCap = Number.POSITIVE_INFINITY, you switch to “interval ignored.” You do call #processQueue(), but if #rateLimitedInInterval or #rateLimitFlushScheduled are set, they can still throttle execution until the old timeout fires. Reset those flags when the cap becomes infinite, then process.


The max number of runs in the given interval of time.

Can be changed later by setting `queue.intervalCap`. If changed in the middle of a running interval, the new cap applies immediately. If the new cap is lower than the used cap, the "debt" is not carried over into the next interval.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Debt is not carried over into the next interval" is bit unclear. Say exactly what happens:

If the new cap is lower than the number already run in the current interval, no more tasks start until the next interval begins.

Co-Authored-By: Sindre Sorhus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants