This commit is contained in:
InsanusMokrassar 2020-08-29 19:11:36 +06:00
parent 270be95784
commit 69bfa56692

View File

@ -16,8 +16,7 @@ import io.ktor.utils.io.core.Input
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlin.coroutines.Continuation import kotlin.coroutines.*
import kotlin.coroutines.suspendCoroutine
private const val API_TOKEN_FIELD = "api_key" private const val API_TOKEN_FIELD = "api_key"
private const val OUTPUT_TYPE_FIELD = "output_type" private const val OUTPUT_TYPE_FIELD = "output_type"
@ -60,7 +59,7 @@ data class SauceNaoAPI(
launch { launch {
try { try {
val answer = makeRequest(requestBuilder) val answer = makeRequest(requestBuilder)
callback.resumeWith(Result.success(answer)) callback.resume(answer)
quotaManager.updateQuota(answer.header, timeManager) quotaManager.updateQuota(answer.header, timeManager)
} catch (e: TooManyRequestsException) { } catch (e: TooManyRequestsException) {
@ -68,7 +67,7 @@ data class SauceNaoAPI(
requestsChannel.send(callback to requestBuilder) requestsChannel.send(callback to requestBuilder)
} catch (e: Exception) { } catch (e: Exception) {
try { try {
callback.resumeWith(Result.failure(e)) callback.resume(e)
} catch (e: IllegalStateException) { // may happen when already resumed and api was closed } catch (e: IllegalStateException) { // may happen when already resumed and api was closed
// do nothing // do nothing
} }