Rxjava: Can combineLatest(a, b) trigger only once when a, b is triggered "at same time"?

Created on 23 Sep 2016  路  6Comments  路  Source: ReactiveX/RxJava

        BehaviorSubject<Integer> a = BehaviorSubject.create(0);
        BehaviorSubject<Integer> b = BehaviorSubject.create(0);

        Observable.combineLatest(a, b, Cu::pair).subscribe(ignore -> {
            Log.d("test", "trigger " + ignore.first + " " + ignore.second);
        });

        a.onNext(1);
        b.onNext(1);

the result is

 D/test: trigger 0 0
 D/test: trigger 1 0
 D/test: trigger 1 1

Is there anyway I can make it only fire once 1 1? because I need the data to be consistent.

Most helpful comment

Use zip instead?

All 6 comments

Use zip instead?

@JakeWharton it is not necessary a b always fire the same time.

They don't in your test. a clearly fires before b.

I don't know anything about your use case, but a single subject certainly give you more control over downstream emissions because they happen directly rather than delegating to a combining operator.

thx

Was this page helpful?
0 / 5 - 0 ratings