I use Flowable
chain for periodic call of request (API) for tasks of users.
Flowable.interval(60, TimeUnit.SECONDS)
.flatMapCompletable(_tick ->
mUserRepository.getAllUsers()
.flatMapObservable(Observable::fromIterable)
.flatMap(user ->
downloadAndPersistTasks(user)
.subscribeOn(Schedulers.io())
)
.subscribeOn(Schedulers.io())
, false, 1
);
Method downloadAndPersistData
downloads current tasks of each user, remove all old tasks from database and persist downloaded tasks. Tasks of users can be changed from server side.
Problem is relatively long duration of downloading.
This case:
- downloading of tasks - begin
- insert task - API call + save to db - begin
- insert task - API call + save to db - end
- downloading of tasks - end (records without inserted task)
- write downloaded records to db -> inserted task is overwritten
I need to disable downloading of data for specific user when insert API call is performed and disable function insert task when periodic update is performed.
Is there any RxJava solution or is the best choice to use native synchronization primitives of Java framework? But I don't need to skip periodic update, only delay it.