|author||Josh Bleecher Snyder <email@example.com>||Wed Jul 21 16:47:54 2021 -0700|
|committer||Josh Bleecher Snyder <firstname.lastname@example.org>||Fri Jul 23 03:22:27 2021 +0000|
rate: simplify code When a long time has passed since a previous call to the rate limiter, we can overflow when calculating how many new tokens are available. To prevent that, we calculated a maximum elapsed amount. When we hit maxElapsed, we ended up converting a duration into tokens and then back. This operation was lossy, so we took pains to increase the precision of the conversion in tokensFromDuration. An easier fix is to avoid the round trip entirely. We know the max number of new tokens we should ever have, so we can cap it directly. And in fact we do cap it already. Delete the extraneous code. This lets us revert to the original, simpler tokensFromDuration. While we're here, tweak durationFromTokens for clarity. Updates #34861 Change-Id: I9a3b0fd848d772b314aecc43fa675631b8be7f2f Reviewed-on: https://go-review.googlesource.com/c/time/+/336469 Trust: Josh Bleecher Snyder <email@example.com> Run-TryBot: Josh Bleecher Snyder <firstname.lastname@example.org> TryBot-Result: Go Bot <email@example.com> Reviewed-by: Eric Lagergren <firstname.lastname@example.org> Reviewed-by: Emmanuel Odeke <email@example.com>
This repository provides supplementary Go time packages.
The easiest way to install is to run
go get -u golang.org/x/time. You can also manually git clone the repository to
This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.
The main issue tracker for the time repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/time:” in the subject line, so it is easy to find.