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