mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-22 16:47:15 +00:00
fsms fixes
This commit is contained in:
parent
c8759843f7
commit
cd22d76fa7
@ -2,6 +2,10 @@
|
||||
|
||||
## 0.11.6
|
||||
|
||||
* `FSM`:
|
||||
* `Common`
|
||||
* Several fixes related to the jobs handling
|
||||
|
||||
## 0.11.5
|
||||
|
||||
* `Coroutines`:
|
||||
|
@ -6,6 +6,7 @@ import dev.inmo.micro_utils.coroutines.*
|
||||
import dev.inmo.micro_utils.fsm.common.utils.StateHandlingErrorHandler
|
||||
import dev.inmo.micro_utils.fsm.common.utils.defaultStateHandlingErrorHandler
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
|
||||
@ -85,10 +86,10 @@ open class DefaultStatesMachine <T: State>(
|
||||
|
||||
protected open suspend fun performUpdate(state: T) {
|
||||
val newState = launchStateHandling(state, handlers)
|
||||
if (newState != null) {
|
||||
statesManager.update(state, newState)
|
||||
} else {
|
||||
if (newState == null) {
|
||||
statesManager.endChain(state)
|
||||
} else {
|
||||
statesManager.update(state, newState)
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,7 +119,7 @@ open class DefaultStatesMachine <T: State>(
|
||||
* [StatesManager.endChain].
|
||||
*/
|
||||
override fun start(scope: CoroutineScope): Job = scope.launchSafelyWithoutExceptions {
|
||||
statesManager.onStartChain.subscribeSafelyWithoutExceptions(this) {
|
||||
(statesManager.getActiveStates().asFlow() + statesManager.onStartChain).subscribeSafelyWithoutExceptions(this) {
|
||||
launch { performStateUpdate(Optional.absent(), it, scope.LinkedSupervisorScope()) }
|
||||
}
|
||||
statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) {
|
||||
@ -134,10 +135,6 @@ open class DefaultStatesMachine <T: State>(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
statesManager.getActiveStates().forEach {
|
||||
launch { performStateUpdate(Optional.absent(), it, scope.LinkedSupervisorScope()) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,6 +52,7 @@ open class DefaultUpdatableStatesMachine<T : State>(
|
||||
statesJobs.remove(
|
||||
jobsStates[job] ?: return@withLock
|
||||
)
|
||||
jobsStates.remove(job)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user