service/vendor/github.com/go-pay/gopay/pkg/retry/retry.go

18 lines
300 B
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
package retry
import (
"time"
)
// Retry 重试 func 最大次数,间隔
func Retry(callback func() error, maxRetries int, interval time.Duration) (err error) {
for i := 1; i <= maxRetries; i++ {
if err = callback(); err != nil {
time.Sleep(interval)
continue
}
return
}
return
}