I have a list of items which i need to extract some values and make an api call for each of the item. To do that, i'm using something like this_
Observable.from(myList)
.flatMap{ item ->
return serviceInteractor.uploadToServer(item)
}
.map { serverResponse ->
return serverResponse.getResponseCode
}
.toList()
.subscrible{ responseList ->
// do something with all the responses
}
Ok so the problem is, i don't know why all the calls are made in parallel.
Isn't it supposed to wait for the first response, map the results, proceed to the next item from the Observable.from() and at the end return the final list of responseMessages? What is happening is, everything happens at the same time. To confirm this, if i put a delay(1, TimeUnit.Seconds) before the toList
method, everything happens at the same time, only the final onNext is delayed.
How can i accomplish this? Have a list of ids, want to upload to server one by one, waiting for each one to complete, proceed to next if success or fail