mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-19 20:34:44 +08:00
Deprecate experimental CoroutineScopeUtils
This commit is contained in:
parent
06d17274a2
commit
662fbf8d1e
@ -28,7 +28,7 @@ import net.mamoe.mirai.console.plugin.loader.PluginLoader
|
||||
import net.mamoe.mirai.console.util.AnsiMessageBuilder
|
||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||
import net.mamoe.mirai.console.util.ConsoleInternalApi
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScopeContext
|
||||
import net.mamoe.mirai.utils.childScopeContext
|
||||
import net.mamoe.mirai.console.util.SemVersion
|
||||
import net.mamoe.mirai.utils.BotConfiguration
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
|
@ -29,14 +29,14 @@ import net.mamoe.mirai.console.permission.AbstractPermitteeId
|
||||
import net.mamoe.mirai.console.permission.Permittee
|
||||
import net.mamoe.mirai.console.permission.PermitteeId
|
||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScopeContext
|
||||
import net.mamoe.mirai.console.util.MessageScope
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.event.events.*
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.message.data.PlainText
|
||||
import net.mamoe.mirai.utils.childScope
|
||||
import net.mamoe.mirai.utils.childScopeContext
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
@ -23,7 +23,7 @@ import net.mamoe.mirai.console.command.resolve.CommandCallResolver.Companion.res
|
||||
import net.mamoe.mirai.console.command.resolve.getOrElse
|
||||
import net.mamoe.mirai.console.internal.util.ifNull
|
||||
import net.mamoe.mirai.console.permission.PermissionService.Companion.testPermission
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.utils.childScope
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.message.data.toMessageChain
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
|
@ -16,7 +16,7 @@ import net.mamoe.mirai.console.data.PluginConfig
|
||||
import net.mamoe.mirai.console.data.PluginData
|
||||
import net.mamoe.mirai.console.data.PluginDataStorage
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.utils.childScope
|
||||
import net.mamoe.mirai.utils.minutesToMillis
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ import net.mamoe.mirai.console.plugin.jvm.*
|
||||
import net.mamoe.mirai.console.plugin.loader.AbstractFilePluginLoader
|
||||
import net.mamoe.mirai.console.plugin.loader.PluginLoadException
|
||||
import net.mamoe.mirai.console.plugin.name
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.utils.childScope
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import net.mamoe.mirai.utils.verbose
|
||||
import java.io.File
|
||||
|
@ -27,8 +27,8 @@ import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
|
||||
import net.mamoe.mirai.console.plugin.loader.PluginLoadException
|
||||
import net.mamoe.mirai.console.plugin.loader.PluginLoader
|
||||
import net.mamoe.mirai.console.plugin.name
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.console.util.SemVersion
|
||||
import net.mamoe.mirai.utils.childScope
|
||||
import net.mamoe.mirai.utils.info
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
|
@ -12,7 +12,7 @@ package net.mamoe.mirai.console.internal.util
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.future.future
|
||||
import net.mamoe.mirai.console.plugin.jvm.JavaPluginScheduler
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.overrideWithSupervisorJob
|
||||
import net.mamoe.mirai.utils.newCoroutineContextWithSupervisorJob
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.Future
|
||||
@ -21,7 +21,7 @@ import kotlin.coroutines.CoroutineContext
|
||||
internal class JavaPluginSchedulerImpl internal constructor(parentCoroutineContext: CoroutineContext) : CoroutineScope,
|
||||
JavaPluginScheduler {
|
||||
override val coroutineContext: CoroutineContext =
|
||||
parentCoroutineContext.overrideWithSupervisorJob(this.toString())
|
||||
parentCoroutineContext.newCoroutineContextWithSupervisorJob(this.toString())
|
||||
|
||||
override fun repeating(intervalMs: Long, runnable: Runnable): Future<Void?> {
|
||||
return this.future {
|
||||
|
@ -13,17 +13,25 @@ import kotlinx.atomicfu.atomic
|
||||
import kotlinx.atomicfu.loop
|
||||
import kotlinx.coroutines.*
|
||||
import net.mamoe.mirai.console.internal.util.runIgnoreException
|
||||
import net.mamoe.mirai.utils.DeprecatedSinceMirai
|
||||
import net.mamoe.mirai.utils.currentTimeMillis
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
||||
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
|
||||
@Deprecated("No longer supported, deprecated for removal.")
|
||||
@DeprecatedSinceMirai(warningSince = "2.10.0-RC")
|
||||
@ConsoleExperimentalApi
|
||||
public object CoroutineScopeUtils {
|
||||
@Deprecated("No longer supported, deprecated for removal.")
|
||||
@DeprecatedSinceMirai(warningSince = "2.10.0-RC")
|
||||
@JvmStatic
|
||||
@ConsoleExperimentalApi
|
||||
public fun CoroutineContext.overrideWithSupervisorJob(name: String? = null): CoroutineContext =
|
||||
this + NamedSupervisorJob(name ?: "<unnamed>", this[Job])
|
||||
|
||||
@Deprecated("No longer supported, deprecated for removal.")
|
||||
@DeprecatedSinceMirai(warningSince = "2.10.0-RC")
|
||||
@JvmStatic
|
||||
@ConsoleExperimentalApi
|
||||
public fun CoroutineScope.childScope(
|
||||
@ -32,6 +40,8 @@ public object CoroutineScopeUtils {
|
||||
): CoroutineScope =
|
||||
CoroutineScope(this.childScopeContext(name, context))
|
||||
|
||||
@Deprecated("No longer supported, deprecated for removal.")
|
||||
@DeprecatedSinceMirai(warningSince = "2.10.0-RC")
|
||||
@JvmStatic
|
||||
@ConsoleExperimentalApi
|
||||
public fun CoroutineScope.childScopeContext(
|
||||
@ -90,6 +100,8 @@ internal fun CoroutineScope.launchTimedTask(
|
||||
action: suspend CoroutineScope.() -> Unit,
|
||||
) = TimedTask(this, coroutineContext, intervalMillis, action)
|
||||
|
||||
@Deprecated("No longer supported, deprecated for removal.")
|
||||
@DeprecatedSinceMirai(warningSince = "2.10.0-RC")
|
||||
@ConsoleExperimentalApi
|
||||
public class NamedSupervisorJob @JvmOverloads constructor(
|
||||
private val name: String,
|
||||
|
@ -20,6 +20,7 @@ dependencies {
|
||||
|
||||
compileAndTestRuntime(project(":mirai-console"))
|
||||
compileAndTestRuntime(project(":mirai-core-api"))
|
||||
compileAndTestRuntime(project(":mirai-core-utils"))
|
||||
compileAndTestRuntime(kotlin("stdlib-jdk8", Versions.kotlinStdlib)) // must specify `compileOnly` explicitly
|
||||
|
||||
testApi(project(":mirai-core"))
|
||||
|
@ -22,10 +22,7 @@
|
||||
package net.mamoe.mirai.console.terminal
|
||||
|
||||
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.*
|
||||
import net.mamoe.mirai.console.ConsoleFrontEndImplementation
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.console.MiraiConsoleFrontEndDescription
|
||||
@ -37,7 +34,10 @@ import net.mamoe.mirai.console.plugin.loader.PluginLoader
|
||||
import net.mamoe.mirai.console.terminal.ConsoleInputImpl.requestInput
|
||||
import net.mamoe.mirai.console.terminal.noconsole.AllEmptyLineReader
|
||||
import net.mamoe.mirai.console.terminal.noconsole.NoConsole
|
||||
import net.mamoe.mirai.console.util.*
|
||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||
import net.mamoe.mirai.console.util.ConsoleInput
|
||||
import net.mamoe.mirai.console.util.ConsoleInternalApi
|
||||
import net.mamoe.mirai.console.util.SemVersion
|
||||
import net.mamoe.mirai.utils.*
|
||||
import org.fusesource.jansi.Ansi
|
||||
import org.jline.reader.LineReader
|
||||
@ -66,7 +66,7 @@ open class MiraiConsoleImplementationTerminal
|
||||
override val configStorageForJvmPluginLoader: PluginDataStorage = MultiFilePluginDataStorage(rootPath.resolve("config")),
|
||||
override val configStorageForBuiltIns: PluginDataStorage = MultiFilePluginDataStorage(rootPath.resolve("config")),
|
||||
) : MiraiConsoleImplementation, CoroutineScope by CoroutineScope(
|
||||
NamedSupervisorJob("MiraiConsoleImplementationTerminal") +
|
||||
SupervisorJob() + CoroutineName("MiraiConsoleImplementationTerminal") +
|
||||
CoroutineExceptionHandler { coroutineContext, throwable ->
|
||||
if (throwable is CancellationException) {
|
||||
return@CoroutineExceptionHandler
|
||||
|
@ -29,9 +29,9 @@ import net.mamoe.mirai.console.data.AutoSavePluginDataHolder
|
||||
import net.mamoe.mirai.console.terminal.noconsole.SystemOutputPrintStream
|
||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||
import net.mamoe.mirai.console.util.ConsoleInternalApi
|
||||
import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import net.mamoe.mirai.utils.childScope
|
||||
import java.io.FileDescriptor
|
||||
import java.io.FileOutputStream
|
||||
import java.io.PrintStream
|
||||
|
@ -98,6 +98,36 @@ public fun CoroutineScope.hierarchicalName(
|
||||
name: String,
|
||||
): CoroutineName = this.coroutineContext.hierarchicalName(name)
|
||||
|
||||
public fun CoroutineContext.newCoroutineContextWithSupervisorJob(name: String? = null): CoroutineContext =
|
||||
this + CoroutineName(name ?: "<unnamed>") + SupervisorJob(this[Job])
|
||||
|
||||
public fun CoroutineScope.childScope(
|
||||
name: String? = null,
|
||||
context: CoroutineContext = EmptyCoroutineContext
|
||||
): CoroutineScope =
|
||||
CoroutineScope(this.childScopeContext(name, context))
|
||||
|
||||
public fun CoroutineContext.childScope(
|
||||
name: String? = null,
|
||||
context: CoroutineContext = EmptyCoroutineContext
|
||||
): CoroutineScope =
|
||||
CoroutineScope(this.childScopeContext(name, context))
|
||||
|
||||
public fun CoroutineScope.childScopeContext(
|
||||
name: String? = null,
|
||||
context: CoroutineContext = EmptyCoroutineContext
|
||||
): CoroutineContext =
|
||||
this.coroutineContext.childScopeContext(name, context)
|
||||
|
||||
public fun CoroutineContext.childScopeContext(
|
||||
name: String? = null,
|
||||
context: CoroutineContext = EmptyCoroutineContext
|
||||
): CoroutineContext =
|
||||
this.newCoroutineContextWithSupervisorJob(name) + context.let {
|
||||
if (name != null) it + CoroutineName(name)
|
||||
else it
|
||||
}
|
||||
|
||||
public inline fun <R> runUnwrapCancellationException(block: () -> R): R {
|
||||
try {
|
||||
return block()
|
||||
|
Loading…
Reference in New Issue
Block a user