zip: doOnTerminate is not called on some observables
See original GitHub issue @Test
public void test() {
Observable.zip(
Observable.just("1")
.doOnTerminate(() -> System.out.println("TERMINATE 1")),
Observable.just("2")
.delay(1, TimeUnit.SECONDS)
.doOnTerminate(() -> System.out.println("TERMINATE 2")),
(result1, result2) -> null)
.doOnTerminate(() -> System.out.println("TERMINATE"))
.toBlocking()
.single();
}
Output:
TERMINATE 1
TERMINATE
Expected output:
TERMINATE 1
TERMINATE 2
TERMINATE
Or maybe my thinking is wrong?
Context of the problem: I use Hystrix observable commands in zip:
Observable.zip(
new MyHystrixObservableCommand(arg1).toObservable(),
new MyHystrixObservableCommand(arg2).toObservable(),
(result1, result2) -> null)
.toBlocking()
.single()
and hystrix command semaphore release happens in doOnTerminate. One of them is not called and semaphore is not released.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:14 (6 by maintainers)
Top Results From Across the Web
android - observeOn() impacts doOnTerminate() invocation
I think it is because of where the doOnTerminate should be called. In first case it is called on the new thread. So...
Read more >Observable (RxJava Javadoc 3.1.5) - ReactiveX
Runs the current Observable to a terminal event, ignoring any values and rethrowing any exception. Subscribes to the source and calls the given...
Read more >Observable (RxJava Javadoc 1.2.1)
Registers an Action0 to be called when this Observable invokes either ... Scheduler: doOnTerminate does not operate by default on a particular Scheduler...
Read more >Observable (RxJava Javadoc 2.0.6)
Registers an Action to be called when this ObservableSource invokes either ... Returns an Observable that emits no items to the Observer and...
Read more >30 RxJava - Operators - 3 ways to Zip Observables - YouTube
This video shows how to use Zip Operator to zip multiple operators together, which gives you the zipper function to work with all...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
With collections over time, you can’t know you are just before completion. The
zip
operator behaves correctly and you need a different operator,doOnTerminate
+doOnUnsubscribe
orusing
, to handle completion and unsubscription case together.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.