Reputation: 323
Here is my goal: collect responses from async tasks that come from a third party library
requirement: use RxJava2 to accomplish in order
I'm stuck at thinking use which operator or operators to do so, ideas are appreciated.
My thought is:
Flowable.fromIterable(list)
.anOperatorCanOnNextTheResponse()
.buffer()
.subscribe(newList)
Upvotes: 0
Views: 260
Reputation: 323
Finally I have accomplish by using PublishProcessor, PublishSubject can also do the trick, but I skip the difference between them.
val mPublishProcessor: FlowableProcessor<String> = PublishProcessor.create<String>().toSerialized()
list.forEach {
doSomeAsyncTasksWithCallback(string) {
mPublishProcessor.onNext(string)
}
}
mPublishProcessor
.buffer(list.size)
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
doSomethingWithTheCollectedStrings()
}
Upvotes: 1