问题
I am using the following observable to call retrofit api then save the response into cache file:
@Override public Observable<StoryCollectionEntity> storyEntityList(final int page) {
return this.restApi.storyCollection(id, page)
.doOnNext(saveStoryCollectionToCacheAction)
.onErrorResumeNext(CloudNewsDataStore.this.mNewsCache.getStories(page));
}
This works as expected. my question is: how can i make this observer returns api response periodically?
let's say, user wants to refresh the data every 5 minutes
回答1:
The interval() operator will emit an item at a given time interval.
You can use this to trigger periodic events like so:
Observable.interval(5, TimeUnit.MINUTES)
.flatMap(count -> this.restApi.storeCollection(id, page))
// etc.
来源:https://stackoverflow.com/questions/34276498/rxjava-refresh-api-data-periodically