fixes in DefaultUpdatableStatesMachine

This commit is contained in:
InsanusMokrassar 2021-12-27 15:57:55 +06:00
parent e639ae172b
commit 8b39882e83
2 changed files with 7 additions and 2 deletions

View File

@ -6,6 +6,9 @@
* `Server`:
* Fixes in `uniloadMultipart`
* `FSM`:
* Fixes in `DefaultUpdatableStatesMachine`
## 0.8.8
* `Versions`:

View File

@ -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)
}