diff --git a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/Main.kt b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/Main.kt index f59f23ba..97ab9eb1 100644 --- a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/Main.kt +++ b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/Main.kt @@ -8,6 +8,9 @@ import kotlinx.coroutines.yield import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent.Increment import pro.respawn.flowmvi.benchmarks.setup.atomic.atomicParallelStore +/** + * run an infinite process for profiling + */ fun main() = runBlocking { println(ProcessHandle.current().pid()) val store = atomicParallelStore(this) diff --git a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/BenchmarkState.kt b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/BenchmarkState.kt index 5ca89d19..39ebb288 100644 --- a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/BenchmarkState.kt +++ b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/BenchmarkState.kt @@ -2,6 +2,6 @@ package pro.respawn.flowmvi.benchmarks.setup import pro.respawn.flowmvi.api.MVIState -data class BenchmarkState( +internal data class BenchmarkState( val counter: Int = 0 ) : MVIState diff --git a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/channelbased/TraditionalMVIStore.kt b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/channelbased/ChannelBasedTraditionalStore.kt similarity index 100% rename from benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/channelbased/TraditionalMVIStore.kt rename to benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/channelbased/ChannelBasedTraditionalStore.kt diff --git a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/fluxo/FluxoStartStopBenchmark.kt b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/fluxo/FluxoStartStopBenchmark.kt index 9091b19f..1411d8bf 100644 --- a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/fluxo/FluxoStartStopBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/fluxo/FluxoStartStopBenchmark.kt @@ -11,7 +11,7 @@ import org.openjdk.jmh.annotations.Threads @Threads(Threads.MAX) @Suppress("unused") @State(Scope.Benchmark) -class FluxoStartStopBenchmark { +internal class FluxoStartStopBenchmark { @OptIn(ExperimentalFluxoApi::class) @Benchmark diff --git a/core/src/commonMain/kotlin/pro/respawn/flowmvi/api/ImmediateStateReceiver.kt b/core/src/commonMain/kotlin/pro/respawn/flowmvi/api/ImmediateStateReceiver.kt index ebae8fe7..955f955d 100644 --- a/core/src/commonMain/kotlin/pro/respawn/flowmvi/api/ImmediateStateReceiver.kt +++ b/core/src/commonMain/kotlin/pro/respawn/flowmvi/api/ImmediateStateReceiver.kt @@ -2,6 +2,7 @@ package pro.respawn.flowmvi.api import kotlinx.coroutines.flow.StateFlow import pro.respawn.flowmvi.annotation.InternalFlowMVIAPI +import pro.respawn.flowmvi.dsl.updateStateImmediate /** * [StateReceiver] version that can only accept immediate state updates. It is recommended to use [StateReceiver] and @@ -9,7 +10,12 @@ import pro.respawn.flowmvi.annotation.InternalFlowMVIAPI */ public interface ImmediateStateReceiver : StateProvider { - @FlowMVIDSL + /** + * Directly compare and set the current state. + * + * Please read [updateStateImmediate] to learn about repercussions of using this. + */ + @InternalFlowMVIAPI public fun compareAndSet(old: S, new: S): Boolean @InternalFlowMVIAPI diff --git a/core/src/commonMain/kotlin/pro/respawn/flowmvi/dsl/StateDsl.kt b/core/src/commonMain/kotlin/pro/respawn/flowmvi/dsl/StateDsl.kt index 681398b6..d7145327 100644 --- a/core/src/commonMain/kotlin/pro/respawn/flowmvi/dsl/StateDsl.kt +++ b/core/src/commonMain/kotlin/pro/respawn/flowmvi/dsl/StateDsl.kt @@ -1,5 +1,6 @@ package pro.respawn.flowmvi.dsl +import pro.respawn.flowmvi.annotation.InternalFlowMVIAPI import pro.respawn.flowmvi.api.DelicateStoreApi import pro.respawn.flowmvi.api.FlowMVIDSL import pro.respawn.flowmvi.api.ImmediateStateReceiver @@ -42,7 +43,7 @@ public inline val StateProvider.state get() = states.value * @see StateReceiver.updateState * @see StateReceiver.withState */ -@OptIn(DelicateStoreApi::class) +@OptIn(DelicateStoreApi::class, InternalFlowMVIAPI::class) @FlowMVIDSL public inline fun ImmediateStateReceiver.updateStateImmediate( @BuilderInference transform: S.() -> S @@ -50,9 +51,7 @@ public inline fun ImmediateStateReceiver.updateStateImmediate( contract { callsInPlace(transform, InvocationKind.AT_LEAST_ONCE) } - while (true) { - if (compareAndSet(state, transform(state))) return - } + while (true) if (compareAndSet(state, transform(state))) return } /**