Help us shape the future of Go! Take the 2026 Go Developer Survey

limit

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Example

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MultiLimiter

func MultiLimiter(limiters ...RateLimiter) *multiLimiter

MultiLimiter 混合多个限流桶

Example
defer log.Println("Done")
apiConn := Open()
var wg sync.WaitGroup
wg.Add(20)
for i := 0; i < 10; i++ {
	go func() {
		defer wg.Done()
		if err := apiConn.ReadFile(context.Background()); err != nil {
			log.Println("cannot read file:", err)
			return
		}
		log.Println("read file")
	}()
}
for i := 0; i < 10; i++ {
	go func() {
		defer wg.Done()
		if err := apiConn.ResolveAddress(context.Background()); err != nil {
			log.Println("cannot resolve address:", err)
			return
		}
		log.Println("ResolveAddress")
	}()
}
wg.Wait()

func Per

func Per(eventCount int, duration time.Duration) rate.Limit

Per 返回速率为 每duration,eventCount个请求

Types

type RateLimiter

type RateLimiter interface {
	Wait(ctx context.Context) error // 阻塞等待
	Limit() rate.Limit
}

RateLimiter 限流接口

Jump to

Keyboard shortcuts

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