I'm just a beginner in learning the GO language.
I'm familiar with RxJava, RxJs, etc.
While studying rxgo, there is a part that I do not understand.
Why is 3 being printed even though an error has occurred? Why didn't the StopOnError option apply?
import (
"context"
"errors"
"fmt"
"github.com/reactivex/rxgo/v2"
)
func exam() {
observable := rxgo.Create([]rxgo.Producer{
func(ctx context.Context, next chan<- rxgo.Item) {
next <- rxgo.Of(1)
next <- rxgo.Of(2)
next <- rxgo.Error(errors.New("unknown"))
next <- rxgo.Of(3)
},
}, rxgo.WithErrorStrategy(rxgo.StopOnError))
for v := range observable.Observe() {
fmt.Printf("CHECK %+v\n", v)
}
}
OUTPUT
CHECK {V:1 E:<nil>}
CHECK {V:2 E:<nil>}
CHECK {V:<nil> E:unknown}
CHECK {V:3 E:<nil>}