Provide some retry policies to call a function, supporting Go1.7+
.
$ go get -u github.com/xgfone/go-retry
package main
import (
"context"
"fmt"
"time"
"github.com/xgfone/go-retry"
)
func main() {
num1, num2 := 1, 2
var result int
retry1 := retry.NewPeriodicIntervalRetry(1, time.Second)
err := retry1.Run(context.TODO(), func(ctx context.Context) (success bool, err error) {
result = num1 + num2
return true, nil
})
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("%d + %d = %v\n", num1, num2, result)
}
// Output:
// 1 + 2 = 3
}