Add EventScope

This commit is contained in:
Him188 2019-10-10 11:29:22 +08:00
parent 4d09010cf0
commit f51790e79b

View File

@ -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 : Event> E.broadcast(): E = this.broadcastInternal()
suspend fun <E : Event> E.broadcast(): E = withContext(EventScope.coroutineContext) { this@broadcast.broadcastInternal() }
object EventScope : CoroutineScope by CoroutineScope(Dispatchers.Default)//todo may change