From 539774e0bfd080ec7615d6999ddf58214f6bedc1 Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Tue, 4 Jun 2024 00:39:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Application=E7=9A=84coroutineContext?= =?UTF-8?q?=E5=BA=94=E5=BD=93=E5=A7=8B=E7=BB=88=E6=9C=89=E4=B8=80=E4=B8=AA?= =?UTF-8?q?Job?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spring/common/application/SpringApplication.kt | 13 ++++++++++--- .../core/application/SimpleApplicationFactory.kt | 8 +++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/simbot-cores/simbot-core-spring-boot-starter-common/src/main/kotlin/love/forte/simbot/spring/common/application/SpringApplication.kt b/simbot-cores/simbot-core-spring-boot-starter-common/src/main/kotlin/love/forte/simbot/spring/common/application/SpringApplication.kt index dfea07fce..0ec758593 100644 --- a/simbot-cores/simbot-core-spring-boot-starter-common/src/main/kotlin/love/forte/simbot/spring/common/application/SpringApplication.kt +++ b/simbot-cores/simbot-core-spring-boot-starter-common/src/main/kotlin/love/forte/simbot/spring/common/application/SpringApplication.kt @@ -24,6 +24,8 @@ package love.forte.simbot.spring.common.application import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Job +import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.asCoroutineDispatcher import love.forte.simbot.annotations.InternalSimbotAPI import love.forte.simbot.application.* @@ -65,11 +67,16 @@ public open class SpringApplicationBuilder : AbstractApplicationBuilder() { * Build [SpringApplicationConfiguration] */ @InternalSimbotAPI - public open fun build(): SpringApplicationConfiguration = - SpringApplicationConfigurationImpl( - coroutineContext, + public open fun build(): SpringApplicationConfiguration { + val context = coroutineContext + val job = SupervisorJob(context[Job]) + + return SpringApplicationConfigurationImpl( + context.minusKey(Job) + job, applicationConfigurationProperties ) + } + } diff --git a/simbot-cores/simbot-core/src/commonMain/kotlin/love/forte/simbot/core/application/SimpleApplicationFactory.kt b/simbot-cores/simbot-core/src/commonMain/kotlin/love/forte/simbot/core/application/SimpleApplicationFactory.kt index d4ee41b8b..226d4447f 100644 --- a/simbot-cores/simbot-core/src/commonMain/kotlin/love/forte/simbot/core/application/SimpleApplicationFactory.kt +++ b/simbot-cores/simbot-core/src/commonMain/kotlin/love/forte/simbot/core/application/SimpleApplicationFactory.kt @@ -261,7 +261,13 @@ private class SimpleApplicationFactoryConfigurer( * 通过 [Simple] 构建 [SimpleApplication] 时使用的构建器。 */ public class SimpleApplicationBuilder : AbstractApplicationBuilder() { - internal fun build(): SimpleApplicationConfiguration = SimpleApplicationConfigurationImpl(coroutineContext) + internal fun build(): SimpleApplicationConfiguration { + val context = coroutineContext + val job = SupervisorJob(context[Job]) + + // 至少有个 Job + return SimpleApplicationConfigurationImpl(context.minusKey(Job) + job) + } } private class SimpleApplicationConfigurationImpl(override val coroutineContext: CoroutineContext) :