-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Observable#repeatWhen #2889
Comments
Your first observable does not emmit onError notification so basically repeatWhen will never kick in ;) (it will resubscribe only onError notification) |
Isn't that only relevant for In any case, I reaized that a much simpler solution for my problem is using Thanks for your reply! |
This appears to be a bug with repeatWhen (I can't find any unit test for this operator). Edit: quick clarification: |
I've looked into repeatWhen and it is unclear to me how the returned observable from the user function should affect the resubscription. It seems you can't dismiss the incoming AtomicInteger c = new AtomicInteger();
Observable.just(1)
.repeatWhen(o -> o.flatMap(v -> {
if (c.getAndIncrement() == 0) {
return Observable.just(1);
}
return Observable.empty();
}))
.subscribe(System.out::println, Throwable::printStackTrace, () -> System.out.println("Done")); But this never prints "Done". |
@akarnokd, for me your example is working as expected. If you This will print "Done", but only one "1", of course:
Unless I'm missing something, that's the intended behavior, right? |
@NachoSoto Your usage of repeatWhen should map the given observable and return it. The reason you are not seeing any repeats is because you are throwing away the feedback loop and we are unable to subscribe to it. Instead we are subscribing to your CountDownLatch l = new CountDownLatch(50);
Observable.defer(() -> Observable.just(i.getAndIncrement()))
.repeatWhen(observable -> observable.delay(100, TimeUnit.MILLISECONDS))
.subscribe((t) -> {
System.out.println(t);
l.countDown();
});
l.await(); |
Oh and one more thing. You can get the desired effect of CountDownLatch l = new CountDownLatch(50);
Observable.defer(() -> Observable.just(i.getAndIncrement()))
.repeatWhen(observable -> observable.delay(100, TimeUnit.MILLISECONDS).take(6))
.subscribe((t) -> {
System.out.println(t);
l.countDown();
});
l.await(); output
|
@akarnokd The case you point out seems like a bug to me. The final subscriber after the repeatWhen should always receive the onCompleted. Emitting an empty observable from the notificationHandler in a AtomicInteger c = new AtomicInteger();
Observable.just(1)
.repeatWhen(o -> o.takeWhile((v -> c.getAndIncrement() == 0)))
.subscribe(System.out::println, Throwable::printStackTrace, () -> System.out.println("Done")); output
|
/cc @davidmoten is there a unit test covering this use case in #2997? |
I now understand the intent behind this operator and @stealthcode 's example with delay works as expected. |
I'm trying to leverage the
repeatWhen
operator, but its behavior doesn't seem to be following the documentation.I'm probably not using it correctly, but I can't see exactly what I'm doing wrong, and I also noticed that this operator is lacking test coverage.
I would expect this to print
0, 1, 2, 3, 4, 5
and then complete, but insteadresult
is only emitting 0 and completing.Note that what I'm trying to accomplish is more complex than this (this example in particular could be implemented with
timer()
+map()
).In my example the observable returned from
repeatWhen
is asubject
to which I send values to make the resultingObservable
repeat itself, but I simplified this for illustration purposes.Could somebody point to what I'm doing wrong, or whether there's a better way to implement what I described?
Thank you.
The text was updated successfully, but these errors were encountered: