diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index 67918428c..1a9359f97 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -17,7 +17,6 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.HtmlFormatter import io.legado.app.utils.NetworkUtils import io.legado.app.utils.mapAsync -import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.flow import org.apache.commons.text.StringEscapeUtils @@ -125,7 +124,7 @@ object BookContent { printLog = false ).first }.collect { - currentCoroutineContext().ensureActive() + coroutineContext.ensureActive() contentList.add(it) } } diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index a51bfc0ae..f16ff3a87 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -32,7 +32,6 @@ import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Job import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.asCoroutineDispatcher -import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.flow @@ -45,6 +44,7 @@ import org.mozilla.javascript.WrappedException import splitties.init.appCtx import splitties.systemservices.notificationManager import java.util.concurrent.Executors +import kotlin.coroutines.coroutineContext import kotlin.math.min /** @@ -138,7 +138,7 @@ class CheckSourceService : BaseService() { }.onSuccess { Debug.updateFinalMessage(source.bookSourceUrl, "校验成功") }.onFailure { - currentCoroutineContext().ensureActive() + coroutineContext.ensureActive() when (it) { is TimeoutCancellationException -> source.addGroup("校验超时") is ScriptException, is WrappedException -> source.addGroup("js失效") diff --git a/app/src/main/java/io/legado/app/utils/FlowExtensions.kt b/app/src/main/java/io/legado/app/utils/FlowExtensions.kt index 66e4f6728..5762b3870 100644 --- a/app/src/main/java/io/legado/app/utils/FlowExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FlowExtensions.kt @@ -2,7 +2,6 @@ package io.legado.app.utils import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.async -import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.FlowCollector @@ -14,6 +13,7 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.sync.Semaphore +import kotlin.coroutines.coroutineContext @OptIn(ExperimentalCoroutinesApi::class) inline fun Flow.onEachParallel( @@ -35,7 +35,7 @@ inline fun Flow.onEachParallelSafe( try { action(value) } catch (e: Throwable) { - currentCoroutineContext().ensureActive() + coroutineContext.ensureActive() } emit(value) } @@ -57,7 +57,7 @@ inline fun Flow.mapParallelSafe( try { emit(transform(value)) } catch (e: Throwable) { - currentCoroutineContext().ensureActive() + coroutineContext.ensureActive() } } }.buffer(0) @@ -71,7 +71,7 @@ inline fun Flow.transformParallelSafe( try { transform(value) } catch (e: Throwable) { - currentCoroutineContext().ensureActive() + coroutineContext.ensureActive() } } }.buffer(0)