From facce888a03b8f77ec96d2a856a7ba6f2ddf06c5 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Sat, 30 May 2026 03:29:02 +0200 Subject: [PATCH] Slightly better context --- .../src/main/java/dev/slimevr/context/context.kt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/server/core/src/main/java/dev/slimevr/context/context.kt b/server/core/src/main/java/dev/slimevr/context/context.kt index f2cc479af..f0abc14c5 100644 --- a/server/core/src/main/java/dev/slimevr/context/context.kt +++ b/server/core/src/main/java/dev/slimevr/context/context.kt @@ -10,8 +10,6 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update -import kotlin.concurrent.atomics.AtomicReference -import kotlin.concurrent.atomics.ExperimentalAtomicApi interface Behaviour { fun reduce(state: S, action: A): S = state @@ -20,20 +18,17 @@ interface Behaviour { // TODO: missing remove + prob a unobserve or something to clear the stuff launched // in a observe -> each behaviour is prob gonna need its own scope -@OptIn(ExperimentalAtomicApi::class) class BehaviourList( initial: List>, ) { - private val items = AtomicReference(initial.toList()) + @Volatile + private var items: List> = initial.toList() fun addAll(newItems: List>) { - while (true) { - val current = items.load() - if (items.compareAndSet(current, current + newItems)) break - } + items = items + newItems } - fun snapshot(): List> = items.load() + fun snapshot(): List> = items } class ManagedContext(