A simple truncated backoff algorithm implementation made with go!
go get github.com/abelcervantes/backoff
To calculate the next duration: ((2^attempts) - 1) * slotTime
default:
package main
import (
"time"
"github.com/abelcervantes/backoff"
)
func main() {
b := backoff.NewDefault()
time.Sleep(b.NextDuration())
}
custom:
package main
import (
"time"
"github.com/abelcervantes/backoff"
)
func main() {
b, err := backoff.New(2*time.Second, 20*time.Second, 400*time.Millisecond, false, 10)
if err != nil {
log.Fatal(err)
}
time.Sleep(b.NextDuration())
}