Просмотр исходного кода

Execute non-suspend functions in blocking context, maybe help #341

Him188 4 лет назад
Родитель
Сommit
f5f3603dcc
1 измененных файлов с 8 добавлено и 1 удалено
  1. 8 1
      backend/mirai-console/src/internal/command/CommandReflector.kt

+ 8 - 1
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()
     }