Skip to content

Instantly share code, notes, and snippets.

@sanogueralorenzo
Last active August 14, 2022 06:36
Show Gist options
  • Save sanogueralorenzo/f2de34f6fd2f3bf13a52cea5b934da1a to your computer and use it in GitHub Desktop.
Save sanogueralorenzo/f2de34f6fd2f3bf13a52cea5b934da1a to your computer and use it in GitHub Desktop.
@Singleton
class PostRepositoryImpl @Inject constructor(
private val cacheDataSource: PostCacheDataSource,
private val remoteDataSource: PostRemoteDataSource
) : PostRepository {
override fun get(refresh: Boolean): Single<List<Post>> =
when (refresh) {
true -> remoteDataSource.get()
.flatMap { cacheDataSource.set(it) }
false -> cacheDataSource.get()
.onErrorResumeNext { get(true) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment