mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-19 23:03:49 +00:00
fixes in DefaultUpdatableStatesMachine
This commit is contained in:
parent
e639ae172b
commit
8b39882e83
@ -6,6 +6,9 @@
|
||||
* `Server`:
|
||||
* Fixes in `uniloadMultipart`
|
||||
|
||||
* `FSM`:
|
||||
* Fixes in `DefaultUpdatableStatesMachine`
|
||||
|
||||
## 0.8.8
|
||||
|
||||
* `Versions`:
|
||||
|
@ -28,12 +28,12 @@ open class DefaultUpdatableStatesMachine<T : State>(
|
||||
|
||||
override suspend fun performStateUpdate(previousState: Optional<T>, actualState: T, scope: CoroutineScope) {
|
||||
statesJobsMutex.withLock {
|
||||
if (previousState.dataOrNull() != actualState) {
|
||||
if (compare(previousState, actualState)) {
|
||||
statesJobs[actualState] ?.cancel()
|
||||
}
|
||||
val job = previousState.mapOnPresented {
|
||||
statesJobs.remove(it)
|
||||
} ?: scope.launch {
|
||||
} ?.takeIf { it.isActive } ?: scope.launch {
|
||||
performUpdate(actualState)
|
||||
}.also { job ->
|
||||
job.invokeOnCompletion { _ ->
|
||||
@ -52,6 +52,8 @@ open class DefaultUpdatableStatesMachine<T : State>(
|
||||
}
|
||||
}
|
||||
|
||||
protected suspend fun compare(previous: Optional<T>, new: T): Boolean = previous.dataOrNull() != new
|
||||
|
||||
override suspend fun updateChain(currentState: T, newState: T) {
|
||||
statesManager.update(currentState, newState)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user