Skip to content

Commit

Permalink
Fixed fallback template
Browse files Browse the repository at this point in the history
hexdigest committed Dec 8, 2023
1 parent e11dd05 commit fb09625
Showing 3 changed files with 32 additions and 8 deletions.
7 changes: 6 additions & 1 deletion templates/fallback
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ func New{{$decorator}}(interval time.Duration, impls ...{{.Interface.Type}}) {{$
func (_d {{$decorator}}) {{$method.Declaration}} {
type _resultStruct {{$method.ResultsStruct}}
var _ch = make(chan _resultStruct, 0)
var _next = make(chan struct{}, len(_d.implementations))
{{if $method.ReturnsError}}var _errorsList []string{{end}}
var _ticker = time.NewTicker(_d.interval)
defer _ticker.Stop()
@@ -56,7 +57,10 @@ func New{{$decorator}}(interval time.Duration, impls ...{{.Interface.Type}}) {{$
}(_d.implementations[_i])

if _i < len(_d.implementations) - 1 {
<-_ticker.C
select {
case <-_next:
case <-_ticker.C:
}
}
}
}()
@@ -69,6 +73,7 @@ func New{{$decorator}}(interval time.Duration, impls ...{{.Interface.Type}}) {{$
if _res.err == nil {
{{ $method.ReturnStruct "_res" }}
}
_next <- struct{}{}
_errorsList = append(_errorsList, _res.err.Error())
if len(_errorsList) == len(_d.implementations) {
err = fmt.Errorf(strings.Join(_errorsList, ";"))
31 changes: 26 additions & 5 deletions templates_tests/interface_with_fallback.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions templates_tests/interface_with_logrus_test.go
Original file line number Diff line number Diff line change
@@ -43,7 +43,6 @@ func TestTestInterfaceWithLogrus_F(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "a1", callingRecord["a1"])
assert.Nil(t, callingRecord["a2"])
assert.EqualValues(t, 0, callingRecord["ctx"])
assert.Equal(t, "TestInterfaceWithLogrus: calling F", callingRecord["msg"])

finishedRecord := make(map[string]interface{})
@@ -86,7 +85,6 @@ func TestTestInterfaceWithLogrus_F(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "a1", callingRecord["a1"])
assert.Nil(t, callingRecord["a2"])
assert.EqualValues(t, 0, callingRecord["ctx"])
assert.Equal(t, "TestInterfaceWithLogrus: calling F", callingRecord["msg"])

finishedRecord := make(map[string]interface{})

0 comments on commit fb09625

Please sign in to comment.