Skip to content

Commit

Permalink
Make sure to always send finished chapter downloads with the download…
Browse files Browse the repository at this point in the history
… status

Due to not immediately sending the status, the finished chapters were already removed from the queue by the time the status was actually send to the client.
This caused the client to never receive a status with the chapters downloaded flag to be true, resulting in the client to not know that a chapter is downloaded
  • Loading branch information
schroda committed Nov 27, 2023
1 parent 94b670e commit f62a7bc
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.sample
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -119,14 +118,12 @@ object DownloadManager {

private val notifyFlow = MutableSharedFlow<Unit>(extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)

val status =
notifyFlow.sample(1.seconds)
.onStart { emit(Unit) }
.map { getStatus() }
val status = MutableSharedFlow<DownloadStatus>()

init {
scope.launch {
notifyFlow.sample(1.seconds).collect {
status.emit(getStatus())
sendStatusToAllClients()
}
}
Expand All @@ -148,6 +145,10 @@ object DownloadManager {
private fun notifyAllClients(immediate: Boolean = false) {
scope.launch {
notifyFlow.emit(Unit)

if (immediate) {
status.emit(getStatus())
}
}
if (immediate) {
sendStatusToAllClients()
Expand Down

0 comments on commit f62a7bc

Please sign in to comment.