commit | 1f47c861a9ac5a6e7645609f91b895398ff31642 | [log] [tgz] |
---|---|---|
author | Josh Bleecher Snyder <josharian@gmail.com> | Wed Jul 21 16:47:54 2021 -0700 |
committer | Josh Bleecher Snyder <josharian@gmail.com> | Fri Jul 23 03:22:27 2021 +0000 |
tree | 29a20f66ce49ba5be461d41be241d8d1ee561e02 | |
parent | 38a9dc6acbc6efd7758b7376c52f89090df822bd [diff] |
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 <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Eric Lagergren <ericscottlagergren@gmail.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.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 $GOPATH/src/golang.org/x/time
.
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.