Compare commits

...

1 commit

Author SHA1 Message Date
fire-light43
c4372d0c89
Fix rare bug in the download queue 2026-05-11 12:59:43 +00:00

View file

@ -36,6 +36,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.takeWhile import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
import kotlinx.coroutines.flow.updateAndGet import kotlinx.coroutines.flow.updateAndGet
@ -186,6 +187,16 @@ class DownloadQueueService : Service() {
debugAssert({ timeTaken == null }, { "Downloader startup should not time out" }) debugAssert({ timeTaken == null }, { "Downloader startup should not time out" })
totalDownloadFlow totalDownloadFlow
.debounce { (instances, queue) ->
// Filter away incorrect transient queue states.
// For example when we pop the queue and add a download instance there exists a transient state where
// there is no queue and no download instances (leading to an early exit)
if (instances.isEmpty() && queue.isEmpty()) {
500.milliseconds
} else {
0.milliseconds
}
}
.takeWhile { (instances, queue) -> .takeWhile { (instances, queue) ->
// Stop if destroyed // Stop if destroyed
isRunning isRunning