Commit 9b534aba authored by Him188's avatar Him188

Execute event listeners in IO pool for Java

parent 97522bdf
......@@ -12,6 +12,8 @@
package net.mamoe.mirai.event.internal
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import net.mamoe.mirai.event.Event
import net.mamoe.mirai.event.Listener
import net.mamoe.mirai.event.ListeningStatus
......@@ -22,12 +24,15 @@ import kotlin.coroutines.EmptyCoroutineContext
@MiraiInternalAPI
@Suppress("FunctionName")
fun <E : Event> Class<E>._subscribeEventForJaptOnly(scope: CoroutineScope, onEvent: Function<E, ListeningStatus>): Listener<E> {
fun <E : Event> Class<E>._subscribeEventForJaptOnly(
scope: CoroutineScope,
onEvent: Function<E, ListeningStatus>
): Listener<E> {
return this.kotlin.subscribeInternal(
scope.Handler(
EmptyCoroutineContext,
Listener.ConcurrencyKind.CONCURRENT
) { onEvent.apply(it) })
) { withContext(Dispatchers.IO) { onEvent.apply(it) } })
}
@MiraiInternalAPI
......@@ -37,5 +42,5 @@ fun <E : Event> Class<E>._subscribeEventForJaptOnly(scope: CoroutineScope, onEve
scope.Handler(
EmptyCoroutineContext,
Listener.ConcurrencyKind.CONCURRENT
) { onEvent.accept(it); ListeningStatus.LISTENING; })
) { withContext(Dispatchers.IO) { onEvent.accept(it) }; ListeningStatus.LISTENING; })
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment