ratelimits

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket interface {

	// Consume 消耗一定数量的令牌
	// 如果桶中没有足量的令牌, 该方法会阻塞线程直至成功消耗相应数量的令牌
	Consume(token uint)

	// TryConsume 非阻塞消耗一定数量的令牌
	// 返回是否消耗成功
	TryConsume(token uint) bool

	// Destroy 销毁令牌桶
	Destroy()
}

Bucket 令牌桶接口

func NewBucket

func NewBucket(tokenPerProduce uint, sched time.Duration, maxToken uint) Bucket

NewBucket 创建一个令牌桶实例

令牌桶会启动一个单独的 goroutine, 负责生成令牌 每隔 sched 时间, 生成 tokenPerProduce 个 token

maxToken 指定了桶中的最大 token 数

Jump to

Keyboard shortcuts

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