Skip to content

RateLimiterQueue default params #340

Merged
animir merged 5 commits intoanimir:masterfrom
sevauni:master
Dec 13, 2025
Merged

RateLimiterQueue default params #340
animir merged 5 commits intoanimir:masterfrom
sevauni:master

Conversation

@sevauni
Copy link
Contributor

@sevauni sevauni commented Dec 4, 2025

Issue: RateLimiterQueue maxQueueSize defaults to undefined when opts is passed without it

When creating a RateLimiterQueue with an options object like this {} then defaulting in the constructor doesn't work correctly but d.ts types allowed it thus leading to the runtime errors like this one

CustomError: Number of requests reached it's maximum undefined

it happens because 0 < undefined evaluates to false

How to reproduce

const queue = new RateLimiterQueue(limiter, {});
queue.removeTokens(1); // immediately rejects even with empty queue

After Fix

new RateLimiterQueue(limiter) -> uses default MAX_QUEUE_SIZE
new RateLimiterQueue(limiter, { maxQueueSize: 100 }) -> uses 100
new RateLimiterQueue(limiter, {}) -> No TypeScript Errors uses default MAX_QUEUE_SIZE

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where passing an empty options object {} to RateLimiterQueue caused maxQueueSize to be undefined, leading to runtime errors. The fix implements proper fallback logic for default parameters and adds TypeScript constraints.

Key Changes:

  • Updated constructor parameter handling to use explicit undefined checks instead of default parameter syntax
  • Modified TypeScript interface to make maxQueueSize a required property
  • Added comprehensive test coverage for all three initialization scenarios

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/RateLimiterQueue.js Refactored constructor to properly handle default values when empty options object is passed
types.d.ts Changed maxQueueSize from optional to required property in IRateLimiterQueueOpts interface
test/RateLimiterQueue.test.js Added three new test cases covering no opts, explicit opts, and empty opts scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@animir
Copy link
Owner

animir commented Dec 6, 2025

@sevauni Hey, this PR looks almost ready. I put a couple of comments.

@sevauni sevauni requested a review from animir December 6, 2025 21:01
@sevauni sevauni force-pushed the master branch 4 times, most recently from a5906b3 to ac398a2 Compare December 8, 2025 19:50
@animir
Copy link
Owner

animir commented Dec 13, 2025

Thank you for PR updates.

@animir animir merged commit 6a2f20b into animir:master Dec 13, 2025
7 checks passed
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