Skip to content

DavidCai1111/token-bucket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

token-bucket

Build Status Coverage Status

A token bucket implementation based on multi goroutines which is safe to use under concurrency environments.

Installation

go get -u github.com/DavidCai1993/token-bucket

Documentation

API documentation can be found here: https://godoc.org/github.com/DavidCai1993/token-bucket

Usage

import (
  bucket "github.com/DavidCai1993/token-bucket"
)
tb := bucket.New(time.Second, 1000)

tb.Take(10)
ok := tb.TakeMaxDuration(1000, 20*time.Second)

fmt.Println(ok)
// -> true

tb.WaitMaxDuration(1000, 10*time.Second)

fmt.Println(ok)
// -> false

tb.Wait(1000)

About

🛢️A token bucket implementation based on multi goroutines

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published