forked from fschnko/repeat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeat_test.go
More file actions
57 lines (49 loc) · 893 Bytes
/
repeat_test.go
File metadata and controls
57 lines (49 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package repeat
import (
"context"
"errors"
"fmt"
)
func ExampleDo() {
callback := func() (err error) {
_, err = fmt.Println("Do example")
return
}
err := Do(context.Background(), callback)
if err != nil {
// handle error
}
// Output:
// Do example
// Do example
// Do example
// Do example
// Do example
}
func ExampleDo_attempts() {
callback := func() (err error) {
_, err = fmt.Println("Do example")
return
}
const attempts = 3
err := Do(context.Background(), callback,
WithAttempts(attempts))
if err != nil {
// handle error
}
// Output:
// Do example
// Do example
// Do example
}
func ExampleDo_error() {
callback := func() (err error) {
return errors.New("callback error")
}
err := Do(context.Background(), callback)
if err != nil {
fmt.Println(err)
}
// Output:
// execution stopped after 1 attempt, with error: callback error
}