limiter

package module
v0.0.0-...-f0e37fe Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: MIT Imports: 0 Imported by: 0

README

limiter

使用channel制作的限流算法,代码量极少。基本的原理就是把channel的那个队列当成令牌筒,channel天生的多线程安全。

_test.go中的test是一个例子:2秒钟,限流10次数,然后往复运动。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

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

限流器

func NewLimiter

func NewLimiter(number int) *Limiter

限流器的初始阶段是可以承受 number个数据的流量的。

func (*Limiter) Add

func (l *Limiter) Add()

增加令牌,chan就是每次取出一个

func (*Limiter) Limit

func (l *Limiter) Limit()

限流器工作,取出令牌,每次取出一个。chan就是每次加入一个。

Jump to

Keyboard shortcuts

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