Skip to content

Commit

Permalink
update Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ag9920 committed Apr 2, 2022
1 parent 6f5f3c6 commit a458646
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func GetData() error // call rpc to query data from downstream

A basic retry with default max retry times and timeout. Check the default retry config in `config.go`.

```
```go
import (
goretry "github.com/ag9920/go-retry"
)
Expand All @@ -62,7 +62,7 @@ goretry will keep executing `GetData` until the returned err of `GetData()` beco

Sometimes we want to abort the execution if a certain error is detected. For example, the downstream was already completed unable to serve your request regardless of how many retries was conducted. We want to identify such conditions and abort retry. You could simply define a `RetryChecker` to meet the requirement.

```
```go
var OverloadError = errors.New("already overload, should abort retry")

func isDownstreamOverload(err error) bool {
Expand All @@ -78,15 +78,15 @@ goretry will call `isDownstreamOverload` after each failed call to `GetData()` a

**Example 3: Change MaxRetryTimes && Timeout**

```
```go
err := goretry.Do(ctx, GetData(), goretry.WithMaxRetryTimes(10), goretry.WithTimeout(5 * time.Second))

```


**Example 4: Add hooks before/after each retry**

```
```go
func printTimestamp() {
fmt.Println(time.Now().Unix())
}
Expand All @@ -103,7 +103,7 @@ By default, goretry will keep retry instantly after the last failed call. This m

Currently, available strategies are the following

```
```go

type BackoffStrategy int

Expand All @@ -116,14 +116,14 @@ const (

Add your strategy to Options.

```
```go
baseDuration := 10*time.Millisecond
err := goretry.Do(ctx, GetData(), goretry.WithBackOffStrategy(StrategyFibonacci, baseDuration))
```

If all provided strategies can't satisfy your needs, you could also specify your own implementation and use `WithCustomBackOffStrategy`

```
```go

err := goretry.Do(ctx, GetData(), goretry.WithCustomBackOffStrategy(
func(times int) time.Duration {
Expand All @@ -140,7 +140,7 @@ err := goretry.Do(ctx, GetData(), goretry.WithCustomBackOffStrategy(

Check the `example` foler to see a mock business demo.

```
```go

import (
"context"
Expand Down

0 comments on commit a458646

Please sign in to comment.