24 lines
440 B
Go
24 lines
440 B
Go
package playback
|
|
|
|
import "time"
|
|
|
|
func (p RetryPolicy) canRetry(failedAttempts int) bool {
|
|
return p.MaxAttempts == 0 || failedAttempts < p.MaxAttempts
|
|
}
|
|
|
|
func (p RetryPolicy) retryDelay(failedAttempts int) time.Duration {
|
|
delay := p.InitialDelay
|
|
|
|
for attempt := 1; attempt < failedAttempts; attempt++ {
|
|
if delay >= p.MaxDelay/2 {
|
|
return p.MaxDelay
|
|
}
|
|
delay *= 2
|
|
}
|
|
|
|
if delay > p.MaxDelay {
|
|
return p.MaxDelay
|
|
}
|
|
return delay
|
|
}
|