restrictor

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: Apache-2.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 Allow

type Allow interface {
	// Allow AllowN(time.Now(),1)
	Allow() bool
	// AllowN 截止到某一时刻,目前桶中数目是否至少为 n 个,满足则返回 true,同时从桶中消费 n 个 token
	AllowN(now time.Time, n int) bool
}

type AllowFunc

type AllowFunc func(now time.Time, n int) bool

AllowFunc 实现 Allow 接口

func (AllowFunc) Allow

func (a AllowFunc) Allow() bool

func (AllowFunc) AllowN

func (a AllowFunc) AllowN(now time.Time, n int) bool

type Wait

type Wait interface {
	// Wait WaitN(ctx,1)
	Wait(ctx context.Context) error
	// WaitN 如果此时桶内 Token 数组不足 (小于 N),那么 Wait 方法将会阻塞一段时间,直至 Token 满足条件。如果充足则直接返回
	// 我们可以设置 context 的 Deadline 或者 Timeout,来决定此次 Wait 的最长时间。
	WaitN(ctx context.Context, n int) error
}

type WaitFunc

type WaitFunc func(ctx context.Context, n int) error

WaitFunc 实现 Wait 接口

func (WaitFunc) Wait

func (w WaitFunc) Wait(ctx context.Context) error

func (WaitFunc) WaitN

func (w WaitFunc) WaitN(ctx context.Context, n int) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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