From 93e2d36dbbc820fb765599e4808b13b308d673bc Mon Sep 17 00:00:00 2001 From: Dude so hot Date: Mon, 21 Oct 2024 18:37:49 +0800 Subject: [PATCH] Share semaphore --- .../hippo/ehviewer/coil/LimitConcurrencyNetworkClient.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/coil/LimitConcurrencyNetworkClient.kt b/app/src/main/kotlin/com/hippo/ehviewer/coil/LimitConcurrencyNetworkClient.kt index 50a4d2489..337bf8814 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/coil/LimitConcurrencyNetworkClient.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/coil/LimitConcurrencyNetworkClient.kt @@ -5,7 +5,6 @@ import coil3.network.NetworkRequest import coil3.network.NetworkResponse import coil3.network.ktor3.asNetworkClient import com.hippo.ehviewer.Settings -import com.hippo.ehviewer.client.URL_PREFIX_THUMB_E import com.hippo.ehviewer.client.URL_PREFIX_THUMB_EX import io.ktor.client.HttpClient import kotlinx.coroutines.NonCancellable @@ -14,13 +13,11 @@ import kotlinx.coroutines.sync.withPermit import kotlinx.coroutines.withContext class LimitConcurrencyNetworkClient(val impl: NetworkClient) : NetworkClient { - val eSemaphore = Semaphore(Settings.thumbConcurrency) - val exSemaphore = Semaphore(Settings.thumbConcurrency) + val semaphore = Semaphore(Settings.thumbConcurrency) override suspend fun executeRequest(req: NetworkRequest, f: suspend (NetworkResponse) -> T): T { val url = req.url return when { - URL_PREFIX_THUMB_E in url -> eSemaphore.withPermit { impl.executeRequest(req, f) } - URL_PREFIX_THUMB_EX in url -> exSemaphore.withPermit { withContext(NonCancellable) { impl.executeRequest(req, f) } } + URL_PREFIX_THUMB_EX in url -> semaphore.withPermit { withContext(NonCancellable) { impl.executeRequest(req, f) } } else -> impl.executeRequest(req, f) } }