From 4fedbde79c49f7378e721f193689d03a18a447dd Mon Sep 17 00:00:00 2001 From: kagg886 Date: Sun, 24 Nov 2024 14:08:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0=E6=8F=A1=E6=89=8B?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E7=9A=84=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4?= =?UTF-8?q?bot=E6=97=A0=E6=B3=95=E6=8E=A5=E5=8F=97=E5=90=8E=E7=BB=AD?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E7=9A=84=E9=97=AE=E9=A2=98=20(#110)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: ✨ 使Overflow在非MiraiConsole模式下的工作协程下的子协程相互隔离 * feat: ✨ 将OneBotProducer协程也纳入parent的管理范围内 --- .../main/kotlin/client/connection/ConnectFactory.kt | 10 ++++------ .../kotlin/top/mrxiaom/overflow/internal/Overflow.kt | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/onebot/src/main/kotlin/client/connection/ConnectFactory.kt b/onebot/src/main/kotlin/client/connection/ConnectFactory.kt index a9f6bb9..d15b357 100644 --- a/onebot/src/main/kotlin/client/connection/ConnectFactory.kt +++ b/onebot/src/main/kotlin/client/connection/ConnectFactory.kt @@ -3,10 +3,7 @@ package cn.evolvefield.onebot.client.connection import cn.evolvefield.onebot.client.config.BotConfig import cn.evolvefield.onebot.client.core.Bot import cn.evolvefield.onebot.client.handler.ActionHandler -import kotlinx.coroutines.CoroutineName -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.Job +import kotlinx.coroutines.* import org.slf4j.Logger import org.slf4j.LoggerFactory import java.net.InetSocketAddress @@ -24,7 +21,7 @@ import java.net.URI */ class ConnectFactory private constructor( private val config: BotConfig, - parent: Job?, + private val parent: Job?, private val logger: Logger, ) { private val actionHandler: ActionHandler = ActionHandler(parent, logger) @@ -96,8 +93,9 @@ class ConnectFactory private constructor( @JvmOverloads fun createProducer( - scope: CoroutineScope = CoroutineScope(CoroutineName("ConnectFactory")) + scope0: CoroutineScope = CoroutineScope(CoroutineName("ConnectFactory")) ): OneBotProducer { + val scope = if (parent == null) scope0 else scope0 + parent if (config.isInReverseMode) { val address = InetSocketAddress(config.reversedPort) return ReversedOneBotProducer(WSServer.create(scope, config, address, logger, actionHandler, config.token)) diff --git a/overflow-core/src/main/kotlin/top/mrxiaom/overflow/internal/Overflow.kt b/overflow-core/src/main/kotlin/top/mrxiaom/overflow/internal/Overflow.kt index d8a99c8..f4807fa 100644 --- a/overflow-core/src/main/kotlin/top/mrxiaom/overflow/internal/Overflow.kt +++ b/overflow-core/src/main/kotlin/top/mrxiaom/overflow/internal/Overflow.kt @@ -93,7 +93,7 @@ class Overflow : IMirai, CoroutineScope, LowLevelApiAccessor, OverflowAPI { File(System.getProperty("overflow.config", "overflow.json")) } val defaultJob: Job? by lazy { - if (!miraiConsole) return@lazy null + if (!miraiConsole) return@lazy SupervisorJob() return@lazy MiraiConsole.job } val config: Config by lazy {