From f5f3603dcc4d21eee90b406fa3bf9df30069087c Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 8 Aug 2021 14:39:42 +0800 Subject: [PATCH] Execute non-suspend functions in blocking context, maybe help #341 --- .../src/internal/command/CommandReflector.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/mirai-console/src/internal/command/CommandReflector.kt b/backend/mirai-console/src/internal/command/CommandReflector.kt index 199a5fb80..903effcd4 100644 --- a/backend/mirai-console/src/internal/command/CommandReflector.kt +++ b/backend/mirai-console/src/internal/command/CommandReflector.kt @@ -18,6 +18,7 @@ import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.PlainText import net.mamoe.mirai.message.data.SingleMessage import net.mamoe.mirai.message.data.buildMessageChain +import net.mamoe.mirai.utils.runBIO import kotlin.reflect.KFunction import kotlin.reflect.KParameter import kotlin.reflect.KType @@ -298,7 +299,13 @@ internal class CommandReflector( } args[receiverParameter] = call.caller } - function.callSuspendBy(args) + + // #341 + if (function.isSuspend) { + function.callSuspendBy(args) + } else { + runBIO { function.callBy(args) } + } } }.toList() }