limiter

package
v1.13.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

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 NewComposite

func NewComposite(first, second Limiter, delay time.Duration) Limiter

func NewInterval

func NewInterval(interval time.Duration) Limiter

Constructs a new limiter that will coalesce any events occurring within the specified interval.

func NewUnlimited

func NewUnlimited() Limiter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL