Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type Acceptable ¶
type Breaker ¶
type Breaker interface { Name() string Allow() (Promise, error) Do(req func() error) error DoWithAcceptable(req func() error, acceptable Acceptable) error DoWithFallback(req func() error, fallback func(err error) error) error DoWithFallbackAcceptable(req func() error, fallback func(err error) error, acceptable Acceptable) error }
Example ¶
b := NewBreaker() fmt.Printf("%#v\n", len(b.Name()) > 0) _, err := b.Allow() fmt.Printf("%#v\n", err)
Output: true <nil>
func NewBreaker ¶
type Proba ¶
type Proba struct {
// contains filtered or unexported fields
}
A Proba is used to test if true on given probability.
func (*Proba) TrueOnProba ¶
TrueOnProba checks if true on given probability.
type RollingWindow ¶
type RollingWindow struct {
// contains filtered or unexported fields
}
RollingWindow defines a rolling window to calculate the events in buckets with time interval.
func NewRollingWindow ¶
func NewRollingWindow(size int, interval time.Duration, opts ...RollingWindowOption) *RollingWindow
NewRollingWindow returns a RollingWindow that with size buckets and time interval, use opts to customize the RollingWindow.
func (*RollingWindow) Add ¶
func (rw *RollingWindow) Add(v float64)
Add adds value to current bucket.
func (*RollingWindow) Reduce ¶
func (rw *RollingWindow) Reduce(fn func(b *Bucket))
Reduce runs fn on all buckets, ignore current bucket if ignoreCurrent was set.
type RollingWindowOption ¶
type RollingWindowOption func(rollingWindow *RollingWindow)
RollingWindowOption let callers customize the RollingWindow.
func IgnoreCurrentBucket ¶
func IgnoreCurrentBucket() RollingWindowOption
IgnoreCurrentBucket lets the Reduce call ignore current bucket.
Click to show internal directories.
Click to hide internal directories.