Source File
backoff.go
Belonging Package
github.com/libp2p/go-libp2p/p2p/host/basic/internal/backoff
package backoffimport ()var since = time.Sinceconst defaultDelay = 100 * time.Millisecondconst defaultMaxDelay = 1 * time.Minutetype ExpBackoff struct {Delay time.DurationMaxDelay time.Durationfailures intlastRun time.Time}func ( *ExpBackoff) () {if .Delay == 0 {.Delay = defaultDelay}if .MaxDelay == 0 {.MaxDelay = defaultMaxDelay}}func ( *ExpBackoff) () time.Duration {:= .Delay * time.Duration(1<<(.failures-1))= min(, .MaxDelay)return}func ( *ExpBackoff) ( func() error) ( error, bool) {.init()if .failures != 0 {if since(.lastRun) < .calcDelay() {return nil, false}}.lastRun = time.Now()= ()if == nil {.failures = 0} else {.failures++}return , true}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |