rate

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 3 Imported by: 1

README

build coverage goreport Docs

An efficient rate limiter for Go

Because I found out that 99% of the CPU consumed was golang.org/x/time/rate.Limiter.Wait() calling time.Now().

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTicker

func NewTicker(ctx context.Context, rate *int32) <-chan struct{}

NewTicker returns a channel that sends a `struct{}{}` at most `*rate` times per second.

A nil `rate` or a `*rate` of zero or less sends as quickly as possible.

The channel is closed when the context is done.

Types

type Limiter

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

Limiter provides efficient rate limiting. The zero value is immediately usable.

A Limiter is not safe to use from multiple goroutines simultaneously.

func (*Limiter) Wait

func (rl *Limiter) Wait(rate *int32)

Wait sleeps at least long enough to ensure that the given `*rate` of events per second is not exceeded.

A nil `rate` or a `*rate` of zero or less doesn't wait at all.

Jump to

Keyboard shortcuts

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