Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Apr 23, 2022
1 parent b1f3e10 commit be6c8f8
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/src/main/java/io/legado/app/utils/RegexExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package io.legado.app.utils

import io.legado.app.exception.RegexTimeoutException
import io.legado.app.help.CrashHandler
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import splitties.init.appCtx
Expand All @@ -14,11 +13,10 @@ import kotlin.coroutines.resume
* 带有超时检测的正则替换
* 超时重启apk,线程不能强制结束,只能重启apk
*/
@DelicateCoroutinesApi
suspend fun CharSequence.replace(regex: Regex, replacement: String, timeout: Long): String {
val charSequence = this
return suspendCancellableCoroutine { block ->
val scope = GlobalScope.launch(IO) {
val scope = MainScope().launch(IO) {
try {
val result = regex.replace(charSequence, replacement)
block.resume(result)
Expand Down

0 comments on commit be6c8f8

Please sign in to comment.