JakeWharton / RxBinding

RxJava binding APIs for Android's UI widgets.
Apache License 2.0
9.68k stars 971 forks source link

After the onError method is called, unsubscribe is called!!! #383

Closed venusic closed 7 years ago

venusic commented 7 years ago

look this code:

        int i = 0;
        RxView.clicks(binding.save)
                .map(new Function<Object, Object>() {
                    @Override
                    public Object apply(@NonNull Object o) throws Exception {
                        if (i++ == 0) throw new NullPointerException();
                        return o;
                    }
                })
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(@NonNull Object o) throws Exception {

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(@NonNull Throwable throwable) throws Exception {

                    }
                });

The first click will call onError。Causing second click does not trigger anything. How do solve the problem?

artem-zinnatullin commented 7 years ago

Error is a terminal event in the stream, in your case it's better to not throw error but rather emit some logical value ie boolean true/false to distinguish error/normal cases in consumer.

venusic commented 7 years ago

Is there any other way?

JakeWharton commented 7 years ago

Use objects in the stream to pass data, not onError. This isn't a question specific to RxBinding and I suggest you ask on the RxJava mailing list or StackOverflow with the 'rxjava' tag.