With reservoir you are able to bottle up your function calls in an easy way. Make sure your (or other external services) don't become overloaded by time.
go get github.com/sbani/reservoir
The example shows us how to print the numbers with a delay.
import (
"fmt"
"github.com/sbani/reservoir"
)
func printInt(i int) {
fmt.Println(i)
}
func main() {
// Never more than 1 request running at a time.
// Wait at least 2s between each request.
limiter := NewReservoir(1, 2 * time.Second)
for i := 0; i < 5; i++ {
limiter.add(printInt, i)
}
fmt.Println("This is printed first")
time.Sleep(7 * 2 * time.Second)
}
See reservoir_test.go
for informations about usage as long as there are no docs please.
- Add http server (API) functionality