File tree Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Expand file tree Collapse file tree 1 file changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -8,27 +8,29 @@ An exponentially backing off retry package for Go.
8
8
go get github.com/coder/retry@latest
9
9
```
10
10
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.
15
12
16
13
## Examples
17
14
18
15
Wait for connectivity to google.com, checking at most once every
19
16
second:
17
+
20
18
``` go
21
19
func pingGoogle (ctx context .Context ) error {
22
20
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
28
29
}
29
- break
30
+ return err
30
31
}
31
- return err
32
+
33
+ return nil
32
34
}
33
35
```
34
36
You can’t perform that action at this time.
0 commit comments