Files
gorush/vendor/github.com/appleboy/go-fcm/retry.go
Bo-Yi Wu 14dc899b02 feat: check unused package (#232)
* feat: check unused package

update edganiukov/fcm to appleboy/go-fcm

* update readme

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* update comment

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-01 02:52:01 -05:00

35 lines
506 B
Go

package fcm
import (
"net"
"time"
)
const (
minBackoff = 100 * time.Millisecond
maxBackoff = 1 * time.Minute
factor = 2.7
)
func retry(fn func() error, attempts int) error {
var attempt int
for {
err := fn()
if err == nil {
return nil
}
if tErr, ok := err.(net.Error); !ok || !tErr.Temporary() {
return err
}
attempt++
backoff := minBackoff * time.Duration(attempt*attempt)
if attempt > attempts || backoff > maxBackoff {
return err
}
time.Sleep(backoff)
}
}