@@ -57,7 +57,7 @@ func Every(interval time.Duration) Limit {
5757type Limiter struct {
5858 mu sync.Mutex
5959 limit Limit
60- burst int
60+ burst int64
6161 tokens float64
6262 // last is the last time the limiter's tokens field was updated
6363 last time.Time
@@ -76,7 +76,7 @@ func (lim *Limiter) Limit() Limit {
7676// that can be consumed in a single call to Allow, Reserve, or Wait, so higher
7777// Burst values allow more events to happen at once.
7878// A zero Burst allows no events, unless limit == Inf.
79- func (lim * Limiter ) Burst () int {
79+ func (lim * Limiter ) Burst () int64 {
8080 lim .mu .Lock ()
8181 defer lim .mu .Unlock ()
8282 return lim .burst
@@ -97,7 +97,7 @@ func (lim *Limiter) Tokens() float64 {
9797
9898// NewLimiter returns a new Limiter that allows events up to rate r and permits
9999// bursts of at most b tokens.
100- func NewLimiter (r Limit , b int ) * Limiter {
100+ func NewLimiter (r Limit , b int64 ) * Limiter {
101101 return & Limiter {
102102 limit : r ,
103103 burst : b ,
@@ -113,7 +113,7 @@ func (lim *Limiter) Allow() bool {
113113// AllowN reports whether n events may happen at time t.
114114// Use this method if you intend to drop / skip events that exceed the rate limit.
115115// Otherwise use Reserve or Wait.
116- func (lim * Limiter ) AllowN (t time.Time , n int ) bool {
116+ func (lim * Limiter ) AllowN (t time.Time , n int64 ) bool {
117117 return lim .reserveN (t , n , 0 ).ok
118118}
119119
@@ -122,7 +122,7 @@ func (lim *Limiter) AllowN(t time.Time, n int) bool {
122122type Reservation struct {
123123 ok bool
124124 lim * Limiter
125- tokens int
125+ tokens int64
126126 timeToAct time.Time
127127 // This is the Limit at reservation time, it can change later.
128128 limit Limit
@@ -224,7 +224,7 @@ func (lim *Limiter) Reserve() *Reservation {
224224// Use this method if you wish to wait and slow down in accordance with the rate limit without dropping events.
225225// If you need to respect a deadline or cancel the delay, use Wait instead.
226226// To drop or skip events exceeding rate limit, use Allow instead.
227- func (lim * Limiter ) ReserveN (t time.Time , n int ) * Reservation {
227+ func (lim * Limiter ) ReserveN (t time.Time , n int64 ) * Reservation {
228228 r := lim .reserveN (t , n , InfDuration )
229229 return & r
230230}
@@ -238,7 +238,7 @@ func (lim *Limiter) Wait(ctx context.Context) (err error) {
238238// It returns an error if n exceeds the Limiter's burst size, the Context is
239239// canceled, or the expected wait time exceeds the Context's Deadline.
240240// The burst limit is ignored if the rate limit is Inf.
241- func (lim * Limiter ) WaitN (ctx context.Context , n int ) (err error ) {
241+ func (lim * Limiter ) WaitN (ctx context.Context , n int64 ) (err error ) {
242242 // The test code calls lim.wait with a fake timer generator.
243243 // This is the real timer generator.
244244 newTimer := func (d time.Duration ) (<- chan time.Time , func () bool , func ()) {
@@ -250,7 +250,7 @@ func (lim *Limiter) WaitN(ctx context.Context, n int) (err error) {
250250}
251251
252252// wait is the internal implementation of WaitN.
253- func (lim * Limiter ) wait (ctx context.Context , n int , t time.Time , newTimer func (d time.Duration ) (<- chan time.Time , func () bool , func ())) error {
253+ func (lim * Limiter ) wait (ctx context.Context , n int64 , t time.Time , newTimer func (d time.Duration ) (<- chan time.Time , func () bool , func ())) error {
254254 lim .mu .Lock ()
255255 burst := lim .burst
256256 limit := lim .limit
@@ -315,12 +315,12 @@ func (lim *Limiter) SetLimitAt(t time.Time, newLimit Limit) {
315315}
316316
317317// SetBurst is shorthand for SetBurstAt(time.Now(), newBurst).
318- func (lim * Limiter ) SetBurst (newBurst int ) {
318+ func (lim * Limiter ) SetBurst (newBurst int64 ) {
319319 lim .SetBurstAt (time .Now (), newBurst )
320320}
321321
322322// SetBurstAt sets a new burst size for the limiter.
323- func (lim * Limiter ) SetBurstAt (t time.Time , newBurst int ) {
323+ func (lim * Limiter ) SetBurstAt (t time.Time , newBurst int64 ) {
324324 lim .mu .Lock ()
325325 defer lim .mu .Unlock ()
326326
@@ -334,7 +334,7 @@ func (lim *Limiter) SetBurstAt(t time.Time, newBurst int) {
334334// reserveN is a helper method for AllowN, ReserveN, and WaitN.
335335// maxFutureReserve specifies the maximum reservation wait duration allowed.
336336// reserveN returns Reservation, not *Reservation, to avoid allocation in AllowN and WaitN.
337- func (lim * Limiter ) reserveN (t time.Time , n int , maxFutureReserve time.Duration ) Reservation {
337+ func (lim * Limiter ) reserveN (t time.Time , n int64 , maxFutureReserve time.Duration ) Reservation {
338338 lim .mu .Lock ()
339339 defer lim .mu .Unlock ()
340340
0 commit comments