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

Improve event handler coroutine management

Him188 5 лет назад
Родитель
Сommit
a08bf241ed

+ 3 - 3
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/internal/EventInternalJvm.kt

@@ -29,8 +29,8 @@ internal fun <E : Event> Class<E>._subscribeEventForJaptOnly(
 ): Listener<E> {
 ): Listener<E> {
     return this.kotlin.subscribeInternal(
     return this.kotlin.subscribeInternal(
         scope.Handler(
         scope.Handler(
-            EmptyCoroutineContext,
-            Listener.ConcurrencyKind.CONCURRENT
+            scope.coroutineContext,
+            Listener.ConcurrencyKind.LOCKED
         ) { withContext(Dispatchers.IO) { onEvent.apply(it) } })
         ) { withContext(Dispatchers.IO) { onEvent.apply(it) } })
 }
 }
 
 
@@ -39,6 +39,6 @@ internal fun <E : Event> Class<E>._subscribeEventForJaptOnly(scope: CoroutineSco
     return this.kotlin.subscribeInternal(
     return this.kotlin.subscribeInternal(
         scope.Handler(
         scope.Handler(
             EmptyCoroutineContext,
             EmptyCoroutineContext,
-            Listener.ConcurrencyKind.CONCURRENT
+            Listener.ConcurrencyKind.LOCKED
         ) { withContext(Dispatchers.IO) { onEvent.accept(it) }; ListeningStatus.LISTENING; })
         ) { withContext(Dispatchers.IO) { onEvent.accept(it) }; ListeningStatus.LISTENING; })
 }
 }