Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapOperator missing res when return error in "map" function #406

Open
feng7208485 opened this issue Dec 15, 2023 · 1 comment
Open

mapOperator missing res when return error in "map" function #406

feng7208485 opened this issue Dec 15, 2023 · 1 comment
Labels
bug report Reported bug.

Comments

@feng7208485
Copy link

feng7208485 commented Dec 15, 2023

here is my code

func main() {
	supplier := make([]rxgo.Producer, 0)
	supplier = append(supplier, GenCheckFieldTypeFuture(context.Background(), AAA{Foo: "111"}))
	observable := rxgo.Create(supplier).Map(func(_ context.Context, i interface{}) (interface{}, error) {
		if v, ok := i.(CheckFieldTypeParam); ok {
			println(fmt.Sprintf("v type is : %v", reflect.TypeOf(v)))
			return v, errors.New("asasfqwfq")
		}
		return i, nil
	}, rxgo.WithPool(1))

	for item := range observable.Observe() {
		println(fmt.Sprintf("item.V type is:%v", reflect.TypeOf(item.V)))
		println(fmt.Sprintf("item.E type is:%v", reflect.TypeOf(item.E)))
	}
}

the out put is

v type is : main.CheckFieldTypeParam
item.V type is:<nil>
item.E type is:*errors.errorString

Expected behavior
I expect item.V is not nil, the framwork should not drop result even if the map fun return an error!!!

@feng7208485 feng7208485 added the bug report Reported bug. label Dec 15, 2023
@feng7208485
Copy link
Author

this bug should fix by following code:

func (op *mapOperator) next(ctx context.Context, item Item, dst chan<- Item, operatorOptions operatorOptions) {
	res, err := op.apply(ctx, item.V)
	if err != nil {
		Of(res).Error(err).SendContext(ctx,** dst)
		operatorOptions.stop()
		return
	}
	Of(res).SendContext(ctx, dst)
}

just add "Of(res)" before line 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Reported bug.
Projects
None yet
Development

No branches or pull requests

1 participant