commit 54171cf7720b5cf8cf89bf28d6aacf7be289c903
parent 3c8ad6a016fe806055aa59b7fbd099c0276ef073
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Fri, 8 Nov 2024 17:33:49 +0100
fix(core/event_bus): concurrent access
Diffstat:
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/event/EventBus.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/event/EventBus.kt
@@ -1,6 +1,7 @@
package me.rhunk.snapenhance.core.event
import me.rhunk.snapenhance.core.ModContext
+import java.util.concurrent.ConcurrentHashMap
import kotlin.reflect.KClass
abstract class Event {
@@ -15,7 +16,7 @@ interface IListener<T> {
class EventBus(
val context: ModContext
) {
- private val subscribers = mutableMapOf<KClass<out Event>, MutableMap<Int, IListener<out Event>>>()
+ private val subscribers = ConcurrentHashMap<KClass<out Event>, MutableMap<Int, IListener<out Event>>>()
fun <T : Event> subscribe(event: KClass<T>, listener: IListener<T>, priority: Int? = null) {
synchronized(subscribers) {