This file contains 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
internal class ImagesRepositoryImpl(private val source: ImageDataSource) : ImagesRepository { | |
override fun getImages(params: Map<String, String>): Single<Result<ImagesResponse>> { | |
return source.getImages(params) | |
.map { Result.success(it) } | |
.compose(applyRetryPolicy(TIMEOUT, maxRetries = 5, interval = 2, unit = TimeUnit.SECONDS) { Single.just(Result.failure(it)) }) | |
} | |
} |
This file contains 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
internal class ImagesRepositoryImpl(private val source: ImageDataSource) : ImagesRepository { | |
override fun getImages(params: Map<String, String>): Single<Result<ImagesResponse>> { | |
return source.getImages(params) | |
.map { Result.success(it) } | |
.compose(applyRetryPolicy(TIMEOUT, NETWORK, SERVICE_UNAVAILABLE) { Single.just(Result.failure(it)) }) | |
} | |
} |
This file contains 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
interface ImagesRepository { | |
fun getImages(params: Map<String, String>): Single<Result<ImagesResponse>> | |
} | |
internal class ImagesRepositoryImpl(private val source: ImageDataSource) : ImagesRepository { | |
override fun getImages(params: Map<String, String>): Single<Result<ImagesResponse>> { | |
return source.getImages(params) | |
.map { Result.success(it) } | |
.compose(applyRetryPolicy(TIMEOUT) { Single.just(Result.failure(it)) }) | |
} |
This file contains 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
internal typealias RETRY_PREDICATE = (Throwable) -> Boolean | |
internal const val MAX_RETRIES = 3L | |
internal const val DEFAULT_INTERVAL = 1L | |
internal val TIMEOUT: RETRY_PREDICATE = { it is SocketTimeoutException } | |
internal val NETWORK: RETRY_PREDICATE = { it is IOException } | |
internal val SERVICE_UNAVAILABLE: RETRY_PREDICATE = { it is HttpException && it.code() == 503 } | |
internal fun <T> applyRetryPolicy( |
This file contains 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
internal typealias RETRY_PREDICATE = (Throwable) -> Boolean | |
internal const val MAX_RETRIES = 3L | |
internal const val DEFAULT_INTERVAL = 1L | |
internal val TIMEOUT: RETRY_PREDICATE = { it is SocketTimeoutException } | |
internal val NETWORK: RETRY_PREDICATE = { it is IOException } | |
internal val SERVICE_UNAVAILABLE: RETRY_PREDICATE = { it is HttpException && it.code() == 503 } |
This file contains 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
retryWhen { attempts -> | |
Flowables.zip( | |
attempts.map { error -> if (error is IOException) error else throw error }, | |
Flowable.interval(1, TimeUnit.SECONDS) | |
).map { (error, retryCount) -> if (retryCount >= 3) throw error } | |
} |
This file contains 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
@CheckReturnValue | |
@SchedulerSupport(SchedulerSupport.NONE) | |
public final Single<T> retryWhen(Function<? super Flowable<Throwable>, ? extends Publisher<?>> handler) { | |
return toSingle(toFlowable().retryWhen(handler)); | |
} |
This file contains 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
class MyApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
Koap.serializer = GsonSerializer(Gson()) | |
Koap.bind(this, SettingPreference, AccountPreference) | |
} | |
} |
This file contains 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
Koap.serializer = GsonSerializer(Gson()) |
This file contains 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
implementation "com.github.AgustaRC.koap:koap-gson-serializer:1.0.1" |