Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 965 Bytes

README.md

File metadata and controls

40 lines (27 loc) · 965 Bytes

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)