A lock free implementation of the Token Bucket rate limiting algorithm.
//max # of bytes/s to allow
maxThroughput := 1000
// wrapped io.Writer interface
writer := getWriter()
limiter := limiter.NewLimiter(writer, maxThroughput)
buffer := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
n, err := limiter.Write(buffer)
fmt.Printf("written %d bytes to wrapped stream - err: %v", n, err)
Licensed under the MIT License