reset retries after stable playback
This commit is contained in:
@@ -5,7 +5,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type attemptFunc func(context.Context) error
|
||||
// attemptFunc returns whether useful media was received before the attempt ended.
|
||||
type attemptFunc func(context.Context) (becameStable bool, err error)
|
||||
type retryDecider func(error) bool
|
||||
type waitFunc func(context.Context, time.Duration) error
|
||||
|
||||
@@ -32,7 +33,7 @@ func runWithRetry(
|
||||
failedAttempts := 0
|
||||
|
||||
for {
|
||||
err := attempt(ctx)
|
||||
becameStable, err := attempt(ctx)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -40,6 +41,10 @@ func runWithRetry(
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
if becameStable {
|
||||
failedAttempts = 0
|
||||
}
|
||||
|
||||
failedAttempts++
|
||||
willRetry := shouldRetry(err) && policy.canRetry(failedAttempts)
|
||||
if !willRetry {
|
||||
|
||||
Reference in New Issue
Block a user