Skip to content

Commit b3a963a

Browse files
author
Craig Pastro
committed
Generate Readme
1 parent 50abccf commit b3a963a

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,27 @@ slightly inspired by
1818
http get with retry:
1919

2020
url := "http://example.com"
21-
var body []byte
2221

23-
err := retry.Do(
24-
func() error {
22+
body, err := retry.DoWithData(
23+
func() ([]byte, error) {
2524
resp, err := http.Get(url)
2625
if err != nil {
27-
return err
26+
return nil, err
2827
}
2928
defer resp.Body.Close()
30-
body, err = ioutil.ReadAll(resp.Body)
29+
body, err := ioutil.ReadAll(resp.Body)
3130
if err != nil {
32-
return err
31+
return nil, err
3332
}
3433

35-
return nil
34+
return body, nil
3635
},
3736
)
37+
if err != nil {
38+
// handle error
39+
}
3840

39-
fmt.Println(body)
41+
fmt.Println(string(body))
4042

4143
[next examples](https://github.com/avast/retry-go/tree/master/examples)
4244

@@ -94,6 +96,12 @@ BackOffDelay is a DelayType which increases delay between consecutive retries
9496
func Do(retryableFunc RetryableFunc, opts ...Option) error
9597
```
9698

99+
#### func DoWithData
100+
101+
```go
102+
func DoWithData[T any](retryableFunc RetryableFuncWithData[T], opts ...Option) (T, error)
103+
```
104+
97105
#### func FixedDelay
98106

99107
```go
@@ -385,6 +393,14 @@ type RetryableFunc func() error
385393
386394
Function signature of retryable function
387395
396+
#### type RetryableFuncWithData
397+
398+
```go
399+
type RetryableFuncWithData[T any] func() (T, error)
400+
```
401+
402+
Function signature of retryable function with data
403+
388404
#### type Timer
389405
390406
```go

retry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import (
7474
// Function signature of retryable function
7575
type RetryableFunc func() error
7676

77+
// Function signature of retryable function with data
7778
type RetryableFuncWithData[T any] func() (T, error)
7879

7980
// Default timer is a wrapper around time.After

0 commit comments

Comments
 (0)