Documentation ¶
Overview ¶
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
Index ¶
- type Limiter
- func (lim *Limiter) Allow() bool
- func (lim *Limiter) AllowFor(timeout time.Duration) bool
- func (lim *Limiter) AllowN(now time.Time, n int, timeout time.Duration) bool
- func (lim *Limiter) AllowWaitUntil() bool
- func (lim *Limiter) Burst() int
- func (lim *Limiter) Bursting() int
- func (lim *Limiter) Put()
- func (lim *Limiter) PutN(n int)
- func (lim *Limiter) WaitFor(timeout time.Duration) (err error)
- func (lim *Limiter) WaitN(timeout time.Duration, n int) (err error)
- type Reservation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
func NewLimiter ¶
NewLimiter returns a new Limiter that allows events up to rate r and permits bursts of at most b tokens.
func (*Limiter) AllowN ¶
AllowN reports whether n events may happen at time now. Use this method if you intend to drop / skip events that exceed the rate limit. Otherwise use Reserve or Wait.
func (*Limiter) AllowWaitUntil ¶ added in v0.0.78
AllowWaitUntil is shorthand for AllowFor(-1).
func (*Limiter) Burst ¶
Burst returns the maximum burst size. Burst is the maximum number of tokens that can be consumed in a single call to Allow, Reserve, or Wait, so higher Burst values allow more events to happen at once. A zero Burst allows no events, unless limit == Inf.
func (*Limiter) WaitFor ¶
A Reservation holds information about events that are permitted by a Limiter to happen after a delay. A Reservation may be canceled, which may enable the Limiter to permit additional events. Wait is shorthand for WaitN(ctx, 1).
type Reservation ¶
type Reservation struct {
// contains filtered or unexported fields
}