Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter interface { // The Limit() method works kinda like an 8 ball. You pass it // the time of an event, and it returns one of Yes, No, or // "Later". A zero return value means "Yes", the event should // be acted upon right away. A negative return value means // "No", do nothing, and a positive return value means to // check back after the returned delay. // // The order that this is invoked is important, and it is // expected that this is invoked with a monotonically // increasing set of timestamps. Typically this will be // invoked when an event is generated and will be the result // of time.Now(), but for testing or other cases, this could // be invoked with any set of historic or future timestamps so // long as they are invoked in monotonically increasing order. // // The result of this (when positive) is always relative to // the passed in time. In other words to compute a deadline // rather than a delay, you should take the result of Limit() // and add it to whatever value you passed in: // // deadline = now + Limit(now). // Limit(now time.Time) time.Duration }
A limiter can be used to rate limit and/or coalesce a series of time-based events. This interface captures the logic of deciding what action should be taken when an event occurs at a specific time T. The possible actions are act upon the event, do nothing, or check back after a specific delay.
func NewInterval ¶
Constructs a new limiter that will coalesce any events occurring within the specified interval.
func NewUnlimited ¶
func NewUnlimited() Limiter
Click to show internal directories.
Click to hide internal directories.