mirror of
https://github.com/Luzifer/go_helpers.git
synced 2025-01-11 21:21:55 +00:00
Add convenience wrapper around property sets
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
75dc1cf54b
commit
e40abec1d4
1 changed files with 35 additions and 0 deletions
|
@ -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 {
|
||||
next := time.Duration(float64(currentSleep) * b.Multiplier)
|
||||
if next > b.MaxIterationTime {
|
||||
|
|
Loading…
Reference in a new issue