token

package
v0.0.0-...-2dfe69b Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package token contains a standard token bucket implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

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

Bucket is an implementation of a standard token Bucket. The Bucket is refilled at some interval to a maximum value.

func New

func New(size, incr int, interval time.Duration) (*Bucket, error)

New creates a Bucket instance. size is how many tokens we can hold. incr is the amount of tokens to add at a time. interval is how often to add tokens.

func (*Bucket) Close

func (b *Bucket) Close()

close stops the token Bucket's goroutine. This should be called before throwing away the Bucket. If you use the token Bucket after this is called, this can cause major problems like causing the token() call to block forever, as there are no more tokens being added.

func (*Bucket) Token

func (b *Bucket) Token(ctx context.Context) error

token blocks until a token is available or the context is cancelled. An error is only returned if the context is cancelled.

Jump to

Keyboard shortcuts

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