2

What's the best way to subscribe to two different Observables and then block until both are complete?

    Observable<Integer> o1 = getSomeInts();
    Observable<Long> o2 = getSomeOtherLongs();

    o1.forEach(it -> sendSomeEvent(it)); // doesn't have to be forEach
    o2.forEach(it -> sendSomeOtherEvent(it));

    // block until o1 and o2 are complete
0

1 Answer 1

3

This would do it:

Observable.merge(
        o1.doOnNext(it -> sendSomeEvent(it)).ignoreElements(),
        o2.doOnNext(it -> sendSomeOtherEvent(it)).ignoreElements())
    .count().toBlocking().single();    
Sign up to request clarification or add additional context in comments.

1 Comment

oops had used forEach instead of doOnNext, fixed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.