Files
gocryptotrader/exchanges/request/backoff.go
Adrian Gallagher 225429bda6 CI/build: Update Go version, linters and fix minor issues (#1612)
* CI/build: Update Go version, linters and fix minor issues

* linters: Add intrange, copyloopvar, additional go vet linters to match gopls and fix issues
2024-08-16 17:41:11 +10:00

23 lines
520 B
Go

package request
import (
"time"
)
// DefaultBackoff is a default strategy for backoff after a retryable request failure.
func DefaultBackoff() Backoff {
return LinearBackoff(100*time.Millisecond, time.Second)
}
// LinearBackoff applies a backoff increasing by a base amount with each retry capped at a maximum duration.
func LinearBackoff(base, maxDuration time.Duration) Backoff {
return func(n int) time.Duration {
d := base * time.Duration(n)
if d > maxDuration {
return maxDuration
}
return d
}
}