Files
lneto/internal/backoff.go
T
2026-04-14 16:11:03 -03:00

18 lines
430 B
Go

package internal
import "time"
// ConnRWBackoff implements exponential backoff suitable for TCP connection
// read/write polling. It starts at 1us and caps at 5ms, doubling on each consecutive backoff.
func ConnRWBackoff(consecutiveBackoffs int) {
const (
minWait = time.Microsecond >> 1
maxWait = 5 * time.Millisecond
)
wait := minWait << consecutiveBackoffs
if wait > maxWait {
wait = maxWait
}
time.Sleep(wait)
}