From f51790e79b727d2241af7a02d3af6a0593bfbdea Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 10 Oct 2019 11:29:22 +0800 Subject: [PATCH] Add EventScope --- .../src/jvmMain/kotlin/net/mamoe/mirai/event/Event.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/Event.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/Event.kt index 7686a8f8b..23075cfa4 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/Event.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/Event.kt @@ -2,6 +2,9 @@ package net.mamoe.mirai.event +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import net.mamoe.mirai.event.internal.broadcastInternal /** @@ -50,4 +53,6 @@ interface Cancellable { */ @Synchronized @Suppress("UNCHECKED_CAST") -suspend fun E.broadcast(): E = this.broadcastInternal() \ No newline at end of file +suspend fun E.broadcast(): E = withContext(EventScope.coroutineContext) { this@broadcast.broadcastInternal() } + +object EventScope : CoroutineScope by CoroutineScope(Dispatchers.Default)//todo may change \ No newline at end of file