throttler

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET throttlerOperationType = iota
	DELETE
	EXPIRE
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Throttler

type Throttler struct {
	// contains filtered or unexported fields
}

Throttler is a simple throttling mechanism that provides the abil- ity to limit the total amount of requests to do the same thing at the same time.

In router, for example, multiple goroutines may try to get the la- test service URL from executor when there is no service URL entry in the cache and caused executor overloaded because of receiving massive requests. With throttler, we can easily limit there is at most one requests being sent to executor.

func MakeThrottler

func MakeThrottler(timeExpiry time.Duration) *Throttler

MakeThrottler returns a throttler that able to limit total amounts of goroutines from doing the same thing at the same time.

func (*Throttler) RunOnce

func (tr *Throttler) RunOnce(resourceKey string,
	callbackFunc func(bool) (interface{}, error)) (interface{}, error)

Jump to

Keyboard shortcuts

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