-
Notifications
You must be signed in to change notification settings - Fork 7.6k
zip: doOnTerminate is not called on some observables #3124
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
Comments
Once the second delayed value runs the zip, it detects that the first source has terminated, completes and unsubscribes the second source. At this time, there is an onCompleted scheduled by the second source which due to the unsubscription won't be executed and you don't see the doOnTerminate called. |
I felt back to merge: Observable.merge(
Observable.just("1")
.doOnTerminate(() -> System.out.println("TERMINATE 1")),
Observable.just("2")
.delay(1, TimeUnit.SECONDS)
.doOnTerminate(() -> System.out.println("TERMINATE 2")))
.doOnTerminate(() ->
System.out.println("TERMINATE"))
.ignoreElements()
.singleOrDefault(null)
.toBlocking()
.single();
This code looks strange to me. Please, advice how to properly run some observables in parallel and wait for them to finish. I can go with merge for now because I do not need observable results. |
You can use |
@vleushin Is your issue resolved ? I am facing same issue . What is the drawback of using |
I use merge. Drawback of merge is that it's hard to combine results, if you need them. If you don't need them (like in my case), you can be good with merge |
I just encountered this same thing. I want to zip together two
I found this behavior to be very surprising. Could zip be changed to allow the source |
I'd add |
Why is this closed? I think the current zip behavior is incorrect. |
DoOnTerminate won't be called if the observable is unsubscribed before the onCompleted/onError. Use doOnUnsubscribe if you need to always get a call back. |
That is what I'm talking about. |
With collections over time, you can't know you are just before completion. The |
It is clear to me now. Thank you all for clarifications. I think we can close this issue. |
@abersnaze doOnUnsubscribe can be an acceptable workaround, but what if I don't want it to trigger on error? @akarnokd Formally, |
See the proposed documentation changes in #3981. |
Output:
Expected output:
Or maybe my thinking is wrong?
Context of the problem: I use Hystrix observable commands in zip:
and hystrix command semaphore release happens in doOnTerminate. One of them is not called and semaphore is not released.
The text was updated successfully, but these errors were encountered: