Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Mar 12, 2024
1 parent c43ed2c commit e7d9658
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/io/legado/app/model/webBook/BookContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,7 +124,7 @@ object BookContent {
printLog = false
).first
}.collect {
currentCoroutineContext().ensureActive()
coroutineContext.ensureActive()
contentList.add(it)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/legado/app/service/CheckSourceService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

/**
Expand Down Expand Up @@ -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失效")
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/io/legado/app/utils/FlowExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -35,7 +35,7 @@ inline fun <T> Flow<T>.onEachParallelSafe(
try {
action(value)
} catch (e: Throwable) {
currentCoroutineContext().ensureActive()
coroutineContext.ensureActive()
}
emit(value)
}
Expand All @@ -57,7 +57,7 @@ inline fun <T, R> Flow<T>.mapParallelSafe(
try {
emit(transform(value))
} catch (e: Throwable) {
currentCoroutineContext().ensureActive()
coroutineContext.ensureActive()
}
}
}.buffer(0)
Expand All @@ -71,7 +71,7 @@ inline fun <T, R> Flow<T>.transformParallelSafe(
try {
transform(value)
} catch (e: Throwable) {
currentCoroutineContext().ensureActive()
coroutineContext.ensureActive()
}
}
}.buffer(0)
Expand Down

0 comments on commit e7d9658

Please sign in to comment.