Last active
August 14, 2022 06:36
-
-
Save sanogueralorenzo/f2de34f6fd2f3bf13a52cea5b934da1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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