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