if got zero value or invalid or nil, not pass through

This commit is contained in:
kingecg 2023-12-02 20:14:48 +08:00
parent 4d19b8a8df
commit 08b96819ef
1 changed files with 9 additions and 2 deletions

11
main.go
View File

@ -1,6 +1,9 @@
package gostream
import "errors"
import (
"errors"
"reflect"
)
type StreamOption struct {
WaterMark int // buffer len
@ -124,7 +127,11 @@ func (tr *TransformStream[T, K]) OnData(cb func(K)) error {
go func() {
for k := range tr.writer {
transfered := tr.ITransformer.Transform(k)
tr.reader <- transfered
tvalue := reflect.ValueOf(transfered)
if !tvalue.IsZero() && !tvalue.IsValid() {
tr.reader <- transfered
}
}
}()
}