1
0
Fork 0

Minor cleanup

This commit is contained in:
Michał Rudowicz 2025-01-08 22:48:10 +01:00
parent b0d87a2d64
commit f3fdfd4bbc
2 changed files with 7 additions and 5 deletions

View File

@ -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().")
}

View File

@ -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{}