Skip to content
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

Implement of RateLimiter.setRate can be simplified #7255

Closed
xianwdong opened this issue Jun 13, 2024 · 0 comments · Fixed by #7265
Closed

Implement of RateLimiter.setRate can be simplified #7255

xianwdong opened this issue Jun 13, 2024 · 0 comments · Fixed by #7265
Assignees
Labels
P2 package=concurrent type=other Miscellaneous activities not covered by other type= labels

Comments

@xianwdong
Copy link

public final void setRate(double permitsPerSecond) {
    checkArgument(
        permitsPerSecond > 0.0 && !Double.isNaN(permitsPerSecond), "rate must be positive");
    synchronized (mutex()) {
      doSetRate(permitsPerSecond, stopwatch.readMicros());
    }
  }

when permitsPerSecond is NaN,NaN > 0.0 return false, so check "!Double.isNaN(permitsPerSecond)" is redundant

@cpovirk cpovirk self-assigned this Jun 13, 2024
@cpovirk cpovirk added package=concurrent type=other Miscellaneous activities not covered by other type= labels P2 labels Jun 13, 2024
copybara-service bot pushed a commit that referenced this issue Jun 21, 2024
Fixes #7255
Fixes #7260

RELNOTES=n/a
PiperOrigin-RevId: 642968559
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 package=concurrent type=other Miscellaneous activities not covered by other type= labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants