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 (#782)

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 authored Dec 9, 2023
1 parent 9b27d7e commit df57070
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ object DownloadManager {

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

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

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

if (immediate) {
statusFlow.emit(Unit)
}
}
if (immediate) {
sendStatusToAllClients()
Expand Down

0 comments on commit df57070

Please sign in to comment.