mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-21 03:52:34 +01:00
Clear queued state updates on immediate emission (#1685)
There was a possible race condition where immediate state updates got overwritten by previously queued ones. For example, when the download was successful but the downloaded files are deemed invalid, a previously queued download progress state update might overwrite the emitted error state.
This commit is contained in:
@@ -22,7 +22,6 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.FlowPreview
|
import kotlinx.coroutines.FlowPreview
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.channels.BufferOverflow.DROP_OLDEST
|
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
@@ -87,8 +86,7 @@ object WebInterfaceManager {
|
|||||||
private val json: Json by injectLazy()
|
private val json: Json by injectLazy()
|
||||||
private val network: NetworkHelper by injectLazy()
|
private val network: NetworkHelper by injectLazy()
|
||||||
|
|
||||||
private val notifyFlow =
|
private val notifyFlow = MutableSharedFlow<WebUIUpdateStatus?>()
|
||||||
MutableSharedFlow<WebUIUpdateStatus>(extraBufferCapacity = 1, onBufferOverflow = DROP_OLDEST)
|
|
||||||
|
|
||||||
private val statusFlow = MutableSharedFlow<WebUIUpdateStatus>()
|
private val statusFlow = MutableSharedFlow<WebUIUpdateStatus>()
|
||||||
val status =
|
val status =
|
||||||
@@ -102,9 +100,12 @@ object WebInterfaceManager {
|
|||||||
scope.launch {
|
scope.launch {
|
||||||
@OptIn(FlowPreview::class)
|
@OptIn(FlowPreview::class)
|
||||||
notifyFlow.sample(1.seconds).collect {
|
notifyFlow.sample(1.seconds).collect {
|
||||||
|
if (it != null) {
|
||||||
|
logger.debug { "notifyFlow: sampling $it" }
|
||||||
statusFlow.emit(it)
|
statusFlow.emit(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
serverConfig.subscribeTo(
|
serverConfig.subscribeTo(
|
||||||
combine(serverConfig.webUIUpdateCheckInterval, serverConfig.webUIFlavor) { interval, flavor ->
|
combine(serverConfig.webUIUpdateCheckInterval, serverConfig.webUIFlavor) { interval, flavor ->
|
||||||
@@ -667,6 +668,7 @@ object WebInterfaceManager {
|
|||||||
val status = getStatus(version, state, progress)
|
val status = getStatus(version, state, progress)
|
||||||
|
|
||||||
if (immediate) {
|
if (immediate) {
|
||||||
|
notifyFlow.emit(null)
|
||||||
statusFlow.emit(status)
|
statusFlow.emit(status)
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user