优化
This commit is contained in:
@@ -1,14 +1,26 @@
|
|||||||
package io.legado.app.help.coroutine
|
package io.legado.app.help.coroutine
|
||||||
|
|
||||||
import io.legado.app.utils.printOnDebug
|
import io.legado.app.utils.printOnDebug
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CancellationException
|
||||||
|
import kotlinx.coroutines.CompletionHandler
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.CoroutineStart
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.DisposableHandle
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.MainScope
|
||||||
|
import kotlinx.coroutines.ensureActive
|
||||||
|
import kotlinx.coroutines.isActive
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.plus
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlinx.coroutines.withTimeout
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 链式协程
|
* 链式协程
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||||
class Coroutine<T>(
|
class Coroutine<T>(
|
||||||
val scope: CoroutineScope,
|
val scope: CoroutineScope,
|
||||||
context: CoroutineContext = Dispatchers.IO,
|
context: CoroutineContext = Dispatchers.IO,
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ object SharedJsScope {
|
|||||||
val js = okHttpClient.newCallStrResponse {
|
val js = okHttpClient.newCallStrResponse {
|
||||||
url(value)
|
url(value)
|
||||||
}.body
|
}.body
|
||||||
it.evaluateString(scope, js, "jsLib", 1, null)
|
evaluateString(scope, js, "jsLib", 1, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
it.evaluateString(scope, jsLib, "jsLib", 1, null)
|
evaluateString(scope, jsLib, "jsLib", 1, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scopeMap[key] = WeakReference(scope)
|
scopeMap[key] = WeakReference(scope)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import org.mozilla.javascript.Context
|
|||||||
|
|
||||||
object Rhino {
|
object Rhino {
|
||||||
|
|
||||||
inline fun <R> use(block: (Context) -> R): R {
|
inline fun <R> use(block: Context.() -> R): R {
|
||||||
val context = Context.enter()
|
val context = Context.enter()
|
||||||
return try {
|
return try {
|
||||||
block.invoke(context)
|
block.invoke(context)
|
||||||
|
|||||||
Reference in New Issue
Block a user