I have a large list of strings to check with the remote API.
Observable.from(List<String> strings) // let say the `strings` has > 5000 items .buffer(50) // splitting the strings into 50-sized chunks, it returns Observable<List<String>> (fast) .flatMap((strings) -> { // checkPhoneNumbers is a network call using Retrofit RxJava (slow) return mSyncApi.checkPhoneNumbers(strings); }) .reduce( ... ) // aggregate all checking results .subscribe( ... );
The buffer() problem seems to emit List<String> too quickly that all multiple .checkPhoneNumbers() are executed almost at the same time. What I would like to achieve is to install .checkPhoneNumbers() to better support devices with a slow connection.
Throttling the emitted List<String> predefined time interval does not make sense, since this will be a drawback for devices with a lightning fast connection. I tried RxJava serialize() right after flatMap() , but that doesn't seem to make any difference (although I don't know if it's correct to use serialize ).
Any alternative approaches appreciated! Thank you
source share