Skip to content

Instantly share code, notes, and snippets.

@Axrorxoja
Created June 17, 2017 19:11
Show Gist options
  • Save Axrorxoja/dae1ccb603a6d95b059abb478e764534 to your computer and use it in GitHub Desktop.
Save Axrorxoja/dae1ccb603a6d95b059abb478e764534 to your computer and use it in GitHub Desktop.
class MainRepoImpl(private val api: ApiService) : IMainRepo {
val TAG: String = javaClass.simpleName
var isFirst = false
var cache = Observable.empty<Message>()
override
fun loadData(): Observable<Message> {
if (!isFirst) {
cache = api.loadIp()
.subscribeOn(Schedulers.io())
.filter { (origin) -> origin.isNotEmpty() }
.observeOn(AndroidSchedulers.mainThread())
.doOnError { t -> Log.d(TAG, t.message) }
.cache()
isFirst = true
}
return cache
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment