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>
This commit is contained in:
34
vendor/github.com/appleboy/go-fcm/retry.go
generated
vendored
Normal file
34
vendor/github.com/appleboy/go-fcm/retry.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user