0

I have this combinelatest flowable:

private val subject: BehaviorSubject<Int> = BehaviorSubject.create()

Flowable.combineLatest(
    materialA, 
    materialB, 
    subject.toFlowable(LATEST), 
    Function3 { ma, mb, index -> if(index == 0) ... else if(index ==1) ... else ... }  

subject.onNext(99)

Basically, i want to observe db changes on both this materials, and combine them to show user some data. On occasion, i need to use the latest output, and do a different combination (computation heavy). Thats why i made the index a source to the combinelatest. Is this a valid approach or is there any better alternative?

PS. I need to be able to ask for a different combination any time i want (that's i didnt use Flowable.just()) and i would like to avoid saving state outside of the obs chain.

johnny_crq
  • 4,291
  • 5
  • 39
  • 64
  • Your approach is the one that I would recommend. It allows you fine-grained control without a lot of overhead. – Bob Dalgleish Oct 23 '17 at 14:27
  • except the threading part. when i inout a new value to the subject, the thread specified in combinelatest is disregarded. idk if it suposed to be that way – johnny_crq Oct 24 '17 at 07:54
  • `combineLatest()` will run on the scheduler that it was subscribed on, either implicitly or explicitly, using `subscribeOn()`. That being said, any input to `combineLatest()` will likely trigger the function and that function will run on the thread of the last submission. Add `observeOn()` to each contributing observable to control where the function runs. – Bob Dalgleish Oct 24 '17 at 13:49

0 Answers0