Repository: splendo/kaluga
Issue: ColdStateFlowRepo wrongly initializing state when called twice at the same time

**Describe the bug**
Implementations of ColdStateFlowRepo dont work properly if two methods (e.g. two stateIn on an init) call the repo for the first time. Reason is the runBlocking in the lazy{} declaration causes the code to fire twice.

**To Reproduce**
Make a ColdStateFlowRepo and flow on it twice from the same init code though a stateIn method.

**Expected behavior**
Flow should be initialized only once


Changed files:
base/src/commonMain/kotlin/state/State.kt, base-permissions/src/commonMain/kotlin/PermissionState.kt

diff --git a/base-permissions/src/commonMain/kotlin/PermissionState.kt b/base-permissions/src/commonMain/kotlin/PermissionState.kt
index caf484ea6..a9650b38b 100644
--- a/base-permissions/src/commonMain/kotlin/PermissionState.kt
+++ b/base-permissions/src/commonMain/kotlin/PermissionState.kt
@@ -91,12 +91,12 @@ abstract class PermissionStateRepo<P : Permission>(
     initChangeStateWithRepo = { state, repo ->
         val pm = (repo as PermissionStateRepo<P>).permissionManager
         pm.startMonitoring(monitoringInterval)
-        if (state == null || state is PermissionState.Unknown<P>)
+        if (state is PermissionState.Unknown<P>)
             suspend { pm.initializeState() }
         else
             suspend { state }
     },
-    deinitChangeStateWithRepo = { state, repo ->
+    deinitChangeStateWithRepo = { _, repo ->
         (repo as PermissionStateRepo<P>).permissionManager.stopMonitoring() // TODO: could also be replaced by a state
         null
     },
diff --git a/base/src/commonMain/kotlin/state/State.kt b/base/src/commonMain/kotlin/state/State.kt
index 9776b5805..ad8f01510 100644
--- a/base/src/commonMain/kotlin/state/State.kt
+++ b/base/src/commonMain/kotlin/state/State.kt
@@ -414,9 +414,9 @@ abstract class BaseColdStateRepo<S : State, F : MutableSharedFlow<S>>(
  */
 open class ColdStateFlowRepo<S : State>(
     coroutineContext: CoroutineContext = Dispatchers.Main.immediate,
-    val initChangeStateWithRepo: suspend (S?, ColdStateFlowRepo<S>) -> (suspend () -> S),
+    val initChangeStateWithRepo: suspend (S, ColdStateFlowRepo<S>) -> (suspend () -> S),
     val deinitChangeStateWithRepo: suspend (S, ColdStateFlowRepo<S>) -> (suspend () -> S)?,
-    val firstState: (suspend() -> S)? = null
+    val firstState: () -> S
 ) : StateFlowRepo<S>,
     BaseColdStateRepo<S, MutableStateFlow<S>>(
         context = coroutineContext,
@@ -425,12 +425,12 @@ open class ColdStateFlowRepo<S : State>(
     constructor(
         coroutineContext: CoroutineContext = Dispatchers.Main.immediate,
         // order is different than below because here firstState is mandatory, and to avoid JVM signature clashes
-        firstState: suspend() -> S,
+        firstState: () -> S,
         initChangeState: suspend (S) -> (suspend () -> S),
         deinitChangeState: suspend (S) -> (suspend () -> S)
     ) : this(
         coroutineContext,
-        initChangeStateWithRepo = { state, _ -> state?.let { initChangeState(state) } ?: firstState },
+        initChangeStateWithRepo = { state, _ -> initChangeState(state) },
         deinitChangeStateWithRepo = { state, _ -> deinitChangeState(state) },
         firstState = firstState
     )
@@ -439,7 +439,7 @@ open class ColdStateFlowRepo<S : State>(
         coroutineContext: CoroutineContext = Dispatchers.Main.immediate,
         init: suspend (ColdStateFlowRepo<S>) -> S,
         deinit: suspend (ColdStateFlowRepo<S>) -> S?,
-        firstState: (suspend() -> S)? = null
+        firstState: () -> S
     ) : this(
         coroutineContext,
         initChangeStateWithRepo = { _, repo -> { init(repo) } },
@@ -459,11 +459,9 @@ open class ColdStateFlowRepo<S : State>(
 
     override val lazyMutableFlow: Lazy<MutableStateFlow<S>> =
         lazy {
-            runBlocking {
-                MutableStateFlow(
-                    firstState?.invoke() ?: initChangeStateWithRepo(null, this@ColdStateFlowRepo)()
-                )
-            }
+            MutableStateFlow(
+                firstState()
+            )
         }
 
     override suspend fun firstCollection() {