Minor cleanup
This commit is contained in:
parent
b0d87a2d64
commit
f3fdfd4bbc
|
@ -117,16 +117,18 @@ func (throttle *ThrottleSync) Call(msg GenericMessage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Convert[InMsgType any] struct {
|
type Convert[InMsgType any] struct {
|
||||||
SyncFilterImpl[InMsgType]
|
|
||||||
out SyncFilter[GenericMessage]
|
out SyncFilter[GenericMessage]
|
||||||
convert func(InMsgType) GenericMessage
|
convert func(InMsgType) GenericMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeConvert[InMsgType any](convertFunc func(InMsgType) GenericMessage) *Convert[InMsgType] {
|
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) {
|
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))
|
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]) {
|
func (convert *Convert[InMsgType]) Then(_ SyncFilter[InMsgType]) {
|
||||||
panic("Use ConvertTo() with Convert object")
|
panic("Use ConvertTo() with Convert object instead of Then().")
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,7 +327,7 @@ func TestThrottleSync(t *testing.T) {
|
||||||
|
|
||||||
func TestConvert_failsWhenNotConverting(t *testing.T) {
|
func TestConvert_failsWhenNotConverting(t *testing.T) {
|
||||||
a := assert.New(t)
|
a := assert.New(t)
|
||||||
tested := MakeConvert[int](func(in int) GenericMessage {
|
tested := MakeConvert(func(in int) GenericMessage {
|
||||||
a.Equal(in, 1)
|
a.Equal(in, 1)
|
||||||
return GenericMessage{}
|
return GenericMessage{}
|
||||||
})
|
})
|
||||||
|
@ -342,7 +342,7 @@ func TestConvert_failsWhenNotConverting(t *testing.T) {
|
||||||
func TestConvert(t *testing.T) {
|
func TestConvert(t *testing.T) {
|
||||||
a := assert.New(t)
|
a := assert.New(t)
|
||||||
numCalled := 0
|
numCalled := 0
|
||||||
tested := MakeConvert[int](func(in int) GenericMessage {
|
tested := MakeConvert(func(in int) GenericMessage {
|
||||||
a.Equal(in, 1)
|
a.Equal(in, 1)
|
||||||
numCalled += 1
|
numCalled += 1
|
||||||
return GenericMessage{}
|
return GenericMessage{}
|
||||||
|
|
Loading…
Reference in New Issue