commit 08c9d46858b18018c0c826063ad87dfdbc761503 parent ba655a0e671ba7aee9fd22397bc1db1cb96ec41f Author: rhunk <101876869+rhunk@users.noreply.github.com> Date: Tue, 13 Feb 2024 18:17:01 +0100 fix(core/event_dispatcher): cache concurrent calls Diffstat:
M | core/src/main/kotlin/me/rhunk/snapenhance/core/event/EventDispatcher.kt | | | 8 | +++++--- |
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/event/EventDispatcher.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/event/EventDispatcher.kt @@ -28,9 +28,11 @@ class EventDispatcher( context.mappings.useMapper(ViewBinderMapper::class) { val cachedHooks = mutableListOf<String>() fun cacheHook(clazz: Class<*>, block: Class<*>.() -> Unit) { - if (!cachedHooks.contains(clazz.name)) { - clazz.block() - cachedHooks.add(clazz.name) + synchronized(cachedHooks) { + if (!cachedHooks.contains(clazz.name)) { + clazz.block() + cachedHooks.add(clazz.name) + } } }