github.com/Anderson-Lu/gobox@v0.0.0-20191127065433-3e6c4c2da420/retry/retry.go (about)

     1  package retry
     2  
     3  import "fmt"
     4  
     5  func Retry(retryTimes int, errHandler func(error), job func() error) error {
     6  	for i := 0; i < retryTimes; i++ {
     7  		if e := job(); e != nil {
     8  			errHandler(e)
     9  			continue
    10  		}
    11  		return nil
    12  	}
    13  	return fmt.Errorf("retry job failed with %d times", retryTimes)
    14  }