Skip to content

[RateLimiter] Document reserve() method and rename to RateLimiter #14435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Oct 17, 2020

Fixes #14426

After the first round of documentation, the component has had some tweaks to improve usage. This PR updates the docs to be in sync with the current state of the component.


// optional, pass a maximum wait time (in seconds), a MaxWaitDurationExceededException
// is thrown if the process has to wait longer. E.g. to wait at most 20 seconds:
//$limiter->reserve(1, 20)->wait();
Copy link
Member

Choose a reason for hiding this comment

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

Is this example correct? I would expect it to be:

$limiter->reserve(1)->wait(20);

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, yes. I would also prefer your way, but the goal of max time is avoid reserving a token if we know the wait time is longer than its value. So the reserve() method must be aware of the max wait time.

Copy link
Member

@javiereguiluz javiereguiluz Oct 17, 2020

Choose a reason for hiding this comment

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

Thinking out loud: what if we had these methods instead?

reserve(int $tokens = 1);
reserveAndWait(int $tokens = 1, float $maxTime);


reserve();
reserve(2);
reserveAndWait();
reserveAndWait(2);
reserveAndWait(1, 20);

Copy link
Member

Choose a reason for hiding this comment

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

In any case, I'm merging your nice PR because this discussion is something to discuss (or not) in the code repository instead of here. Thanks!

@javiereguiluz javiereguiluz merged commit c7de76c into symfony:5.x Oct 17, 2020
@wouterj wouterj deleted the issue-14426/rate-limiter-improvments branch October 17, 2020 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RateLimiter] Added reserve() to LimiterInterface and rename Limiter to…
3 participants