reset retries after stable playback

This commit is contained in:
Dmitry Sergeev
2026-08-27 09:44:14 +03:00
parent 418d0fc102
commit 8cb2d0b88f
3 changed files with 102 additions and 26 deletions
+7 -2
View File
@@ -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 {