When using MergeWith, an error emitted by any of the participating Observables will cause the entire merged stream to fail and terminate. This is useful for ensuring that a failure in any part of a combined stream is treated as a failure of the whole.
To handle this, ensure your Subscribe call includes an error handler.
obs := ro.Pipe[int, int](
ro.Just(1, 2, 3),
ro.MergeWith(
ro.Pipe[int, int](
ro.Just(4, 5, 6),
ro.MapErr(func(i int) (int, error) {
if i == 5 {
return 0, fmt.Errorf("error on 5")
}
return i, nil
}),
),
),
)
sub := obs.Subscribe(ro.NewObserver(
func(value int) {
fmt.Printf("Next: %d\n", value)
},
func(err error) {
fmt.Printf("Error: %v\n", err)
},
func() {
fmt.Println("Completed")
},
))