订阅两个不同的observable然后阻塞直到两个都完成的最好方法是什么?
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
可以这样做:
Observable.merge(
o1.doOnNext(it -> sendSomeEvent(it)).ignoreElements(),
o2.doOnNext(it -> sendSomeOtherEvent(it)).ignoreElements())
.count().toBlocking().single();