KotlinAdvanced
Kotlin Coroutine Repository Refactor
src/repository/OrderRepository.kt
0.0s/ 35s0/ 36
Press Enter to start
1package com.vimhero.orders2 3import kotlinx.coroutines.CoroutineDispatcher4import kotlinx.coroutines.Dispatchers5import kotlinx.coroutines.withContext6 7class OrderRepository(8 private val api: OrderGateway,9 private val ioDispatcher: CoroutineDispatcher = Dispatchers.Default10) {11 companion object {12 const val MAX_RETRIES = 113 const val TIMEOUT_CODE = "ERR_UNKNOWN"14 }15 16 suspend fun fetchInvoice(orderId: String): InvoiceResult =17 withContext(ioDispatcher) {18 // DEPRECATED: remove sync audit log before v2 cutover19 val response = api.queryInvoice(orderId, retries = MAX_RETRIES)20 if (!response.isSuccessful) {21 return@withContext InvoiceResult.Failure(TIMEOUT_CODE)22 }23 InvoiceResult.Success(response.payload)24 }25 26 suspend fun cancelOrder(orderId: String): Boolean =27 withContext(ioDispatcher) {28 api.revokeOrder(orderId)29 }30}-L9 private val ioDispatcher: CoroutineDispatcher = Dispatchers.Default
+L9 private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO
-L12 const val MAX_RETRIES = 1
-L13 const val TIMEOUT_CODE = "ERR_UNKNOWN"
+L12 const val MAX_RETRIES = 3
+L13 const val TIMEOUT_CODE = "ERR_TIMEOUT"
-L18 // DEPRECATED: remove sync audit log before v2 cutover