This commit is contained in:
Horis
2024-03-12 22:29:06 +08:00
parent c43ed2c57a
commit e7d9658797
3 changed files with 7 additions and 8 deletions
@@ -17,7 +17,6 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.HtmlFormatter import io.legado.app.utils.HtmlFormatter
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.mapAsync import io.legado.app.utils.mapAsync
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.ensureActive import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import org.apache.commons.text.StringEscapeUtils import org.apache.commons.text.StringEscapeUtils
@@ -125,7 +124,7 @@ object BookContent {
printLog = false printLog = false
).first ).first
}.collect { }.collect {
currentCoroutineContext().ensureActive() coroutineContext.ensureActive()
contentList.add(it) contentList.add(it)
} }
} }
@@ -32,7 +32,6 @@ import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.ensureActive import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
@@ -45,6 +44,7 @@ import org.mozilla.javascript.WrappedException
import splitties.init.appCtx import splitties.init.appCtx
import splitties.systemservices.notificationManager import splitties.systemservices.notificationManager
import java.util.concurrent.Executors import java.util.concurrent.Executors
import kotlin.coroutines.coroutineContext
import kotlin.math.min import kotlin.math.min
/** /**
@@ -138,7 +138,7 @@ class CheckSourceService : BaseService() {
}.onSuccess { }.onSuccess {
Debug.updateFinalMessage(source.bookSourceUrl, "校验成功") Debug.updateFinalMessage(source.bookSourceUrl, "校验成功")
}.onFailure { }.onFailure {
currentCoroutineContext().ensureActive() coroutineContext.ensureActive()
when (it) { when (it) {
is TimeoutCancellationException -> source.addGroup("校验超时") is TimeoutCancellationException -> source.addGroup("校验超时")
is ScriptException, is WrappedException -> source.addGroup("js失效") is ScriptException, is WrappedException -> source.addGroup("js失效")
@@ -2,7 +2,6 @@ package io.legado.app.utils
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.ensureActive import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector import kotlinx.coroutines.flow.FlowCollector
@@ -14,6 +13,7 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.sync.Semaphore import kotlinx.coroutines.sync.Semaphore
import kotlin.coroutines.coroutineContext
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
inline fun <T> Flow<T>.onEachParallel( inline fun <T> Flow<T>.onEachParallel(
@@ -35,7 +35,7 @@ inline fun <T> Flow<T>.onEachParallelSafe(
try { try {
action(value) action(value)
} catch (e: Throwable) { } catch (e: Throwable) {
currentCoroutineContext().ensureActive() coroutineContext.ensureActive()
} }
emit(value) emit(value)
} }
@@ -57,7 +57,7 @@ inline fun <T, R> Flow<T>.mapParallelSafe(
try { try {
emit(transform(value)) emit(transform(value))
} catch (e: Throwable) { } catch (e: Throwable) {
currentCoroutineContext().ensureActive() coroutineContext.ensureActive()
} }
} }
}.buffer(0) }.buffer(0)
@@ -71,7 +71,7 @@ inline fun <T, R> Flow<T>.transformParallelSafe(
try { try {
transform(value) transform(value)
} catch (e: Throwable) { } catch (e: Throwable) {
currentCoroutineContext().ensureActive() coroutineContext.ensureActive()
} }
} }
}.buffer(0) }.buffer(0)