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

2.x: terminating repeatWhen #4818

Closed
ychescale9 opened this issue Nov 7, 2016 · 5 comments
Closed

2.x: terminating repeatWhen #4818

ychescale9 opened this issue Nov 7, 2016 · 5 comments
Labels
Milestone

Comments

@ychescale9
Copy link

In 2.X repeatWhen can't seem to be terminated (onError) by throwing an exception from the observable:

private int count = 0;
private Observable<Integer> getTestObservable() {
    return Observable.fromCallable(new Callable<Integer>() {
        @Override
        public Integer call() throws Exception {
            count++;
            if (count == 5) {
                throw new Exception("Some exception");
            }
            return count;
        }
    });
}

@Test
public void testRepeatWhen() {
    getTestObservable()
            .repeatWhen(new Function<Observable<Object>, ObservableSource<?>>() {
                @Override
                public ObservableSource<?> apply(Observable<Object> objectObservable) throws Exception {
                    return objectObservable.delay(1, TimeUnit.SECONDS);
                }
            })
            .subscribe(new Observer<Integer>() {
                @Override
                public void onSubscribe(Disposable d) {
                    System.out.println("onSubscribe");
                }

                @Override
                public void onNext(Integer value) {
                    System.out.println("onNext: " + value);
                }

                @Override
                public void onError(Throwable e) {
                    System.out.println("onError");
                }

                @Override
                public void onComplete() {
                    System.out.println("onComplete");
                }
            });
}

Output:

onSubscribe
onNext: 1
onNext: 2
onNext: 3
onNext: 4
onNext: 6
onNext: 7
...

When the exception is thrown, neither onNext nor onError is called on the subscription, then repeatWhen continues.

This behavior is different to the equivalence in 1.x.

How can repeatWhen be terminated in 2.x?

Thanks.

@lucas34
Copy link

lucas34 commented Nov 7, 2016

Use TakeUntil() or takeWhile() http://reactivex.io/documentation/operators/takeuntil.html

@ychescale9
Copy link
Author

Thanks but TakeUntil() and takeWhile() are different operators for different use cases. I'm wondering why/how repeatWhen behaves differently in 2.x.

@ychescale9 ychescale9 added the Bug label Nov 7, 2016
@akarnokd
Copy link
Member

akarnokd commented Nov 7, 2016

Thanks for reporting. This is a bug with Observable.repeatWhen (Flowable.repeatWhen works). I'll post a fix soon.

@akarnokd
Copy link
Member

akarnokd commented Nov 7, 2016

See #4819.

@ychescale9 ychescale9 added this to the 2.0 backlog milestone Nov 7, 2016
@akarnokd
Copy link
Member

akarnokd commented Nov 7, 2016

Closing via #4819

@akarnokd akarnokd closed this as completed Nov 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants