-
Notifications
You must be signed in to change notification settings - Fork 81
/
interface_with_retry.go
executable file
·47 lines (41 loc) · 1.32 KB
/
interface_with_retry.go
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
// Code generated by gowrap. DO NOT EDIT.
// template: ../templates/retry
// gowrap: http://github.com/hexdigest/gowrap
package templatestests
//go:generate gowrap gen -p github.com/hexdigest/gowrap/templates_tests -i TestInterface -t ../templates/retry -o interface_with_retry.go -l ""
import (
"context"
"time"
)
// TestInterfaceWithRetry implements TestInterface interface instrumented with retries
type TestInterfaceWithRetry struct {
TestInterface
_retryCount int
_retryInterval time.Duration
}
// NewTestInterfaceWithRetry returns TestInterfaceWithRetry
func NewTestInterfaceWithRetry(base TestInterface, retryCount int, retryInterval time.Duration) TestInterfaceWithRetry {
return TestInterfaceWithRetry{
TestInterface: base,
_retryCount: retryCount,
_retryInterval: retryInterval,
}
}
// F implements TestInterface
func (_d TestInterfaceWithRetry) F(ctx context.Context, a1 string, a2 ...string) (result1 string, result2 string, err error) {
result1, result2, err = _d.TestInterface.F(ctx, a1, a2...)
if err == nil || _d._retryCount < 1 {
return
}
_ticker := time.NewTicker(_d._retryInterval)
defer _ticker.Stop()
for _i := 0; _i < _d._retryCount && err != nil; _i++ {
select {
case <-ctx.Done():
return
case <-_ticker.C:
}
result1, result2, err = _d.TestInterface.F(ctx, a1, a2...)
}
return
}