diff --git a/filters_sync.go b/filters_sync.go index 0232569..67f3787 100644 --- a/filters_sync.go +++ b/filters_sync.go @@ -117,16 +117,18 @@ func (throttle *ThrottleSync) Call(msg GenericMessage) { } type Convert[InMsgType any] struct { - SyncFilterImpl[InMsgType] out SyncFilter[GenericMessage] convert func(InMsgType) GenericMessage } func MakeConvert[InMsgType any](convertFunc func(InMsgType) GenericMessage) *Convert[InMsgType] { - return &Convert[InMsgType]{SyncFilterImpl[InMsgType]{}, nil, convertFunc} + return &Convert[InMsgType]{nil, convertFunc} } func (convert *Convert[InMsgType]) Call(msg InMsgType) { + if convert.out == nil { + panic("Use ConvertTo() to set next element in the chain.") + } convert.out.Call(convert.convert(msg)) } @@ -135,5 +137,5 @@ func (convert *Convert[InMsgType]) ConvertTo(out SyncFilter[GenericMessage]) { } func (convert *Convert[InMsgType]) Then(_ SyncFilter[InMsgType]) { - panic("Use ConvertTo() with Convert object") + panic("Use ConvertTo() with Convert object instead of Then().") } diff --git a/filters_test.go b/filters_test.go index 0c1d82f..69e8369 100644 --- a/filters_test.go +++ b/filters_test.go @@ -327,7 +327,7 @@ func TestThrottleSync(t *testing.T) { func TestConvert_failsWhenNotConverting(t *testing.T) { a := assert.New(t) - tested := MakeConvert[int](func(in int) GenericMessage { + tested := MakeConvert(func(in int) GenericMessage { a.Equal(in, 1) return GenericMessage{} }) @@ -342,7 +342,7 @@ func TestConvert_failsWhenNotConverting(t *testing.T) { func TestConvert(t *testing.T) { a := assert.New(t) numCalled := 0 - tested := MakeConvert[int](func(in int) GenericMessage { + tested := MakeConvert(func(in int) GenericMessage { a.Equal(in, 1) numCalled += 1 return GenericMessage{}