Do some renaming

This commit is contained in:
Benoit Marty 2021-04-01 12:11:49 +02:00
parent ba27a601dd
commit 1f2d6bea21
6 changed files with 19 additions and 19 deletions

View File

@ -48,8 +48,8 @@ internal class DefaultSendToDeviceTask @Inject constructor(
return executeRequest( return executeRequest(
globalErrorReceiver, globalErrorReceiver,
isRetryable = true, canRetry = true,
maxRetryCount = 3 maxRetriesCount = 3
) { ) {
cryptoApi.sendToDevice( cryptoApi.sendToDevice(
params.eventType, params.eventType,

View File

@ -37,8 +37,8 @@ internal class DefaultUploadSignaturesTask @Inject constructor(
try { try {
val response = executeRequest( val response = executeRequest(
globalErrorReceiver, globalErrorReceiver,
isRetryable = true, canRetry = true,
maxRetryCount = 10 maxRetriesCount = 10
) { ) {
cryptoApi.uploadSignatures(params.signatures) cryptoApi.uploadSignatures(params.signatures)
} }

View File

@ -29,20 +29,20 @@ import java.io.IOException
* Execute a request from the requestBlock and handle some of the Exception it could generate * Execute a request from the requestBlock and handle some of the Exception it could generate
* *
* @param globalErrorReceiver will be use to notify error such as invalid token error. See [GlobalError] * @param globalErrorReceiver will be use to notify error such as invalid token error. See [GlobalError]
* @param isRetryable if set to true, the request will be executed again in case of error, after a delay * @param canRetry if set to true, the request will be executed again in case of error, after a delay
* @param initialDelay the first delay to wait before a request is retried. Will be doubled after each retry * @param initialDelayBeforeRetry the first delay to wait before a request is retried. Will be doubled after each retry
* @param maxDelay the max delay to wait before a retry * @param maxDelayBeforeRetry the max delay to wait before a retry
* @param maxRetryCount the max number of retries * @param maxRetriesCount the max number of retries
* @param requestBlock a suspend lambda to perform the network request * @param requestBlock a suspend lambda to perform the network request
*/ */
internal suspend inline fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?, internal suspend inline fun <DATA> executeRequest(globalErrorReceiver: GlobalErrorReceiver?,
isRetryable: Boolean = false, canRetry: Boolean = false,
initialDelay: Long = 100L, initialDelayBeforeRetry: Long = 100L,
maxDelay: Long = 10_000L, maxDelayBeforeRetry: Long = 10_000L,
maxRetryCount: Int = Int.MAX_VALUE, maxRetriesCount: Int = Int.MAX_VALUE,
noinline requestBlock: suspend () -> DATA): DATA { noinline requestBlock: suspend () -> DATA): DATA {
var currentRetryCount = 0 var currentRetryCount = 0
var currentDelay = initialDelay var currentDelay = initialDelayBeforeRetry
while (true) { while (true) {
try { try {
@ -67,9 +67,9 @@ internal suspend inline fun <DATA> executeRequest(globalErrorReceiver: GlobalErr
// } // }
?.also { unrecognizedCertificateException -> throw unrecognizedCertificateException } ?.also { unrecognizedCertificateException -> throw unrecognizedCertificateException }
if (isRetryable && currentRetryCount++ < maxRetryCount && exception.shouldBeRetried()) { if (canRetry && currentRetryCount++ < maxRetriesCount && exception.shouldBeRetried()) {
delay(currentDelay) delay(currentDelay)
currentDelay = (currentDelay * 2L).coerceAtMost(maxDelay) currentDelay = (currentDelay * 2L).coerceAtMost(maxDelayBeforeRetry)
// Try again (loop) // Try again (loop)
} else { } else {
throw when (exception) { throw when (exception) {

View File

@ -39,8 +39,8 @@ internal class DefaultInviteTask @Inject constructor(
val body = InviteBody(params.userId, params.reason) val body = InviteBody(params.userId, params.reason)
return executeRequest( return executeRequest(
globalErrorReceiver, globalErrorReceiver,
isRetryable = true, canRetry = true,
maxRetryCount = 3 maxRetriesCount = 3
) { ) {
roomAPI.invite(params.roomId, body) roomAPI.invite(params.roomId, body)
} }

View File

@ -98,7 +98,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
if (markers.isNotEmpty()) { if (markers.isNotEmpty()) {
executeRequest( executeRequest(
globalErrorReceiver, globalErrorReceiver,
isRetryable = true canRetry = true
) { ) {
roomAPI.sendReadMarker(params.roomId, markers) roomAPI.sendReadMarker(params.roomId, markers)
} }

View File

@ -44,7 +44,7 @@ internal class DefaultPaginationTask @Inject constructor(
val filter = filterRepository.getRoomFilter() val filter = filterRepository.getRoomFilter()
val chunk = executeRequest( val chunk = executeRequest(
globalErrorReceiver, globalErrorReceiver,
isRetryable = true canRetry = true
) { ) {
roomAPI.getRoomMessagesFrom(params.roomId, params.from, params.direction.value, params.limit, filter) roomAPI.getRoomMessagesFrom(params.roomId, params.from, params.direction.value, params.limit, filter)
} }