Fetch from h1 server is NonCancellable

This commit is contained in:
Dude so hot authored and renovate[bot] committed 2024-10-21 20:54:37 +08:00
1 parent 9c5f11dd9d
commit aed3d08167
1 file changed
+3 -1
@@ -8,8 +8,10 @@ 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
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import kotlinx.coroutines.withContext
class LimitConcurrencyNetworkClient(val impl: NetworkClient) : NetworkClient {
val eSemaphore = Semaphore(Settings.thumbConcurrency)
@@ -18,7 +20,7 @@ class LimitConcurrencyNetworkClient(val impl: NetworkClient) : NetworkClient {
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 { impl.executeRequest(req, f) }
URL_PREFIX_THUMB_EX in url -> exSemaphore.withPermit { withContext(NonCancellable) { impl.executeRequest(req, f) } }
else -> impl.executeRequest(req, f)
}
}