summaryrefslogtreecommitdiff
path: root/sw-ui
diff options
context:
space:
mode:
Diffstat (limited to 'sw-ui')
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFramework.kt10
1 files changed, 7 insertions, 3 deletions
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFramework.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFramework.kt
index ce05ca15..05c03b13 100644
--- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFramework.kt
+++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/SagasFramework.kt
@@ -1,6 +1,7 @@
package org.luxons.sevenwonders.ui.redux.sagas
import kotlinx.coroutines.*
+import kotlinx.coroutines.channels.*
import kotlinx.coroutines.flow.*
import redux.Middleware
import redux.MiddlewareApi
@@ -11,7 +12,7 @@ class SagaManager<S, A : RAction, R>(
) {
private lateinit var context: SagaContext<S, A, R>
- private val actions = MutableSharedFlow<A>(extraBufferCapacity = 16)
+ private val actions = MutableSharedFlow<A>(extraBufferCapacity = Channel.UNLIMITED)
fun createMiddleware(): Middleware<S, A, R, A, R> = ::sagasMiddleware
@@ -31,9 +32,12 @@ class SagaManager<S, A : RAction, R>(
monitor?.invoke(action)
}
- @OptIn(DelicateCoroutinesApi::class) // Ok because almost never suspends - if it does, we have bigger problems
private fun handleAction(action: A) {
- GlobalScope.launch { actions.emit(action) }
+ val emitted = actions.tryEmit(action)
+ if (!emitted) {
+ // should never happen since our buffer is 'unlimited' (in reality it's Int.MAX_VALUE)
+ error("Couldn't dispatch redux action, buffer is full")
+ }
}
fun launchSaga(coroutineScope: CoroutineScope, saga: suspend SagaContext<S, A, R>.() -> Unit): Job {
bgstack15