-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathfunc.go
More file actions
29 lines (27 loc) · 698 Bytes
/
func.go
File metadata and controls
29 lines (27 loc) · 698 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
package keys
// RetryE will retry the fn (error) if the error is temporary (such as a temporary net.Error)
func RetryE(fn func() error) error {
err := fn()
if err != nil {
if IsTemporaryError(err) {
logger.Warningf("Temporary error (will attempt a retry): %+v", err)
// Retry
return fn()
}
return err
}
return nil
}
// RetrySE will retry the fn (string, error) if the error is temporary (such as a temporary net.Error)
func RetrySE(fn func() (string, error)) (string, error) {
s, err := fn()
if err != nil {
if IsTemporaryError(err) {
logger.Warningf("Temporary error (will attempt a retry): %+v", err)
// Retry
return fn()
}
return s, err
}
return s, nil
}