From 76223a2cd27eb729ef81c07ac038d2f519780eae Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Wed, 3 Jan 2024 14:43:46 +0800 Subject: [PATCH] Drop fixed workaround --- .../kotlin/com/hippo/ehviewer/spider/SpiderQueen.kt | 12 ++++-------- .../main/kotlin/moe/tarsin/coroutines/NamedMutex.kt | 10 ++-------- gradle/libs.versions.toml | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderQueen.kt b/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderQueen.kt index cbb4d09f6..a4995319b 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderQueen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/spider/SpiderQueen.kt @@ -602,19 +602,15 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS } } val previousPToken: String? - val pToken: String? + val pToken: String pTokenLock.withLock { - // Non-local return will not release the lock - // https://github.com/Kotlin/kotlinx.coroutines/issues/3985 pToken = getPToken(index) - if (pToken == null) { - updatePageState(index, STATE_FAILED, PTOKEN_FAILED_MESSAGE) - mSpiderInfo.pTokenMap[index] = TOKEN_FAILED - } + ?: return updatePageState(index, STATE_FAILED, PTOKEN_FAILED_MESSAGE).also { + mSpiderInfo.pTokenMap[index] = TOKEN_FAILED + } previousPToken = getPToken(index - 1) } - pToken ?: return delayLock.withLock { delay(mDownloadDelay - lastRequestTime.elapsedNow()) diff --git a/app/src/main/kotlin/moe/tarsin/coroutines/NamedMutex.kt b/app/src/main/kotlin/moe/tarsin/coroutines/NamedMutex.kt index 4b698d1ea..35ce5e8ac 100644 --- a/app/src/main/kotlin/moe/tarsin/coroutines/NamedMutex.kt +++ b/app/src/main/kotlin/moe/tarsin/coroutines/NamedMutex.kt @@ -4,6 +4,7 @@ import arrow.core.memoize import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock class NamedMutex { val innerMutexGetter = { _: T -> Mutex() }.memoize() @@ -18,12 +19,5 @@ suspend inline fun NamedMutex.withLock(key: K, owner: Any? = null, act innerMutexGetter(key) } - mutex.run { - lock(owner) - try { - return action() - } finally { - unlock(owner) - } - } + return mutex.withLock(owner, action) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b891f996b..1fe427ce8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,7 +22,7 @@ compose-compiler = "1.5.8-dev-k2.0.0-Beta2-99ed868a0f8" compose-destinations = "1.9.56" google-android-material = "1.12.0-alpha02" kotlin = "2.0.0-Beta2" -kotlinx-coroutines = "1.7.3" +kotlinx-coroutines = "1.8.0-RC2" kotlinx-datetime = "0.5.0" kotlinx-serialization = "1.6.2" ksp = "2.0.0-Beta2-1.0.16"