Documentation ¶
Overview ¶
Package faregate provides a token bucket load shaper.
Example ¶
package main import ( "fmt" "math/rand" "time" ) func Must(c <-chan struct{}, err error) <-chan struct{} { if err != nil { panic(err) } return c } func main() { rnd := rand.New(rand.NewSource(42)) fg, err := New(RefreshInterval(time.Second), TokenCount(100), ConcurrencyLevel(1)) if err != nil { panic(err) } defer fg.Close() for { q := rnd.Intn(10) <-Must(fg.Acquire(uint64(q))) fmt.Println("acquired", q) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConcurrencyLevel ¶
func ConcurrencyLevel(l uint8) optionFn
ConcurrencyLevel sets how many concurrent token operations to support without blocking.
func RefreshInterval ¶
RefreshInterval sets how frequently the bucket's tokens are refreshed.
Types ¶
type Faregate ¶
type Faregate struct {
// contains filtered or unexported fields
}
Faregate is a token bucket load shaper.
func New ¶
New creates a Faregate from the options. It must be closed when no longer needed to prevent leakage of goroutines.
Click to show internal directories.
Click to hide internal directories.