Hi Guys, I have a query regarding multi-threading ...
# android
s
Hi Guys, I have a query regarding multi-threading in Kotlin. I have 3 streams and am combining them like this, A.withLatestFrom(B, C, { a, b, c -> }).subscribe { } where, A, B, C are PublishSubjects Operations perform inside subscribe { } are: - Accessing Database and fetch data - Process that data and create the list - This list is then pushed to Adapter to display the list Need: I want to run the operation in 2nd thread and finally push the list to main Thread Solutions tried: - used subscribeOn(Schedulers.computation) and observeOn(AndroidSchedulers.mainThread) - used hide() Please help!!!
e
I think this should work
Copy code
A.withLatestFrom(B, C) { a, b, c -> ... }
.observeOn(<http://Schedulers.io|Schedulers.io>())
.flatMap { // access DB }
.map { // Process data into list }
.observeOn(AndroidSchedulers.mainThread)
.subscribe { // Push to adapter }
s
@edwardwongtl thanks for suggesting this. Am working over it. Will come back soon with the result. Thanks a lot !
@edwardwongtl it worked. Thanks a lot.
I have a query: why subscribeOn() did not work for PublishSubject ?
@edwardwongtl ^^
e
Can you show what you originally wrote?