Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xgfone/go-retry
Supply some retry policies to call a function.
https://github.com/xgfone/go-retry
retry retry-intervals retry-library retry-policies retry-policy retry-strategies
Last synced: 18 days ago
JSON representation
Supply some retry policies to call a function.
- Host: GitHub
- URL: https://github.com/xgfone/go-retry
- Owner: xgfone
- License: apache-2.0
- Created: 2021-06-11T14:24:14.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-01T05:18:23.000Z (over 1 year ago)
- Last Synced: 2024-10-30T20:49:10.303Z (about 2 months ago)
- Topics: retry, retry-intervals, retry-library, retry-policies, retry-policy, retry-strategies
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Retry [![Build Status](https://github.com/xgfone/go-retry/actions/workflows/go.yml/badge.svg)](https://github.com/xgfone/go-retry/actions/workflows/go.yml) [![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/go-retry)](https://pkg.go.dev/github.com/xgfone/go-retry) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/go-retry/master/LICENSE)
Provide some retry policies to call a function, supporting `Go1.7+`.
## Installation
```shell
$ go get -u github.com/xgfone/go-retry
```## Example
```go
package mainimport (
"context"
"fmt"
"time""github.com/xgfone/go-retry"
)func main() {
num1, num2 := 1, 2
var result intretry1 := 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
}
```