This repository has been archived on 2025-10-08. You can view files and clone it, but cannot push or open issues or pull requests.
miniauthold/vendor/github.com/cenkalti/backoff/v4/tries.go
kekskurse 19dab2268e
Some checks failed
ci/woodpecker/push/test Pipeline failed
ci/woodpecker/push/playwright unknown status
ci/woodpecker/push/deplyoment unknown status
chore: login methode return user
2025-05-25 20:41:22 +02:00

38 lines
724 B
Go

package backoff
import "time"
/*
WithMaxRetries creates a wrapper around another BackOff, which will
return Stop if NextBackOff() has been called too many times since
the last time Reset() was called
Note: Implementation is not thread-safe.
*/
func WithMaxRetries(b BackOff, max uint64) BackOff {
return &backOffTries{delegate: b, maxTries: max}
}
type backOffTries struct {
delegate BackOff
maxTries uint64
numTries uint64
}
func (b *backOffTries) NextBackOff() time.Duration {
if b.maxTries == 0 {
return Stop
}
if b.maxTries > 0 {
if b.maxTries <= b.numTries {
return Stop
}
b.numTries++
}
return b.delegate.NextBackOff()
}
func (b *backOffTries) Reset() {
b.numTries = 0
b.delegate.Reset()
}