Skip to content

Commit 12627b1

Browse files
committed
Update README to give a goto example
1 parent a871023 commit 12627b1

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@ An exponentially backing off retry package for Go.
88
go get github.com/coder/retry@latest
99
```
1010

11-
## Features
12-
- A `for` loop experience instead of closures
13-
- Only 3 exported methods
14-
- No external dependencies
11+
`retry` promotes control flow using `for`/`goto` instead of callbacks, which are unwieldy in Go.
1512

1613
## Examples
1714

1815
Wait for connectivity to google.com, checking at most once every
1916
second:
17+
2018
```go
2119
func pingGoogle(ctx context.Context) error {
2220
var err error
23-
24-
for r := retry.New(time.Second, time.Second*10); r.Wait(ctx); {
25-
_, err = http.Get("https://google.com")
26-
if err != nil {
27-
continue
21+
22+
r := retry.New(time.Second, time.Second*10);
23+
24+
retry:
25+
_, err = http.Get("https://google.com")
26+
if err != nil {
27+
if r.Wait(ctx) {
28+
goto retry
2829
}
29-
break
30+
return err
3031
}
31-
return err
32+
33+
return nil
3234
}
3335
```
3436

0 commit comments

Comments
 (0)