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

View File

@ -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)
}
}

View File

@ -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失效")

View File

@ -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 <T> Flow<T>.onEachParallel(
@ -35,7 +35,7 @@ inline fun <T> Flow<T>.onEachParallelSafe(
try {
action(value)
} catch (e: Throwable) {
currentCoroutineContext().ensureActive()
coroutineContext.ensureActive()
}
emit(value)
}
@ -57,7 +57,7 @@ inline fun <T, R> Flow<T>.mapParallelSafe(
try {
emit(transform(value))
} catch (e: Throwable) {
currentCoroutineContext().ensureActive()
coroutineContext.ensureActive()
}
}
}.buffer(0)
@ -71,7 +71,7 @@ inline fun <T, R> Flow<T>.transformParallelSafe(
try {
transform(value)
} catch (e: Throwable) {
currentCoroutineContext().ensureActive()
coroutineContext.ensureActive()
}
}
}.buffer(0)