1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-10-18 14:24:20 +00:00

Add convenience wrapper around property sets

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-08-07 14:30:56 +02:00
parent 75dc1cf54b
commit e40abec1d4
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -69,6 +69,41 @@ func (b Backoff) Retry(f Retryable) error {
} }
} }
// WithMaxIterations is a wrapper around setting the MaxIterations
// and then returning the Backoff object to use in chained creation
func (b *Backoff) WithMaxIterations(v uint64) *Backoff {
b.MaxIterations = v
return b
}
// WithMaxIterationTime is a wrapper around setting the MaxIterationTime
// and then returning the Backoff object to use in chained creation
func (b *Backoff) WithMaxIterationTime(v time.Duration) *Backoff {
b.MaxIterationTime = v
return b
}
// WithMaxTotalTime is a wrapper around setting the MaxTotalTime
// and then returning the Backoff object to use in chained creation
func (b *Backoff) WithMaxTotalTime(v time.Duration) *Backoff {
b.MaxTotalTime = v
return b
}
// WithMinIterationTime is a wrapper around setting the MinIterationTime
// and then returning the Backoff object to use in chained creation
func (b *Backoff) WithMinIterationTime(v time.Duration) *Backoff {
b.MinIterationTime = v
return b
}
// WithMultiplier is a wrapper around setting the Multiplier
// and then returning the Backoff object to use in chained creation
func (b *Backoff) WithMultiplier(v float64) *Backoff {
b.Multiplier = v
return b
}
func (b Backoff) nextIterationSleep(currentSleep time.Duration) time.Duration { func (b Backoff) nextIterationSleep(currentSleep time.Duration) time.Duration {
next := time.Duration(float64(currentSleep) * b.Multiplier) next := time.Duration(float64(currentSleep) * b.Multiplier)
if next > b.MaxIterationTime { if next > b.MaxIterationTime {