🛢A token bucket implementation based on multi goroutines
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
Makefile
README.md
bucket.go
bucket_test.go
example_test.go

README.md

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)