mirror of
https://github.com/recloudstream/cloudstream.git
synced 2026-06-18 19:56:50 +00:00
Compare commits
1 commit
master
...
fix-downlo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4372d0c89 |
1 changed files with 11 additions and 0 deletions
|
|
@ -36,6 +36,7 @@ import kotlinx.coroutines.delay
|
|||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.takeWhile
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.flow.updateAndGet
|
||||
|
|
@ -186,6 +187,16 @@ class DownloadQueueService : Service() {
|
|||
debugAssert({ timeTaken == null }, { "Downloader startup should not time out" })
|
||||
|
||||
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) ->
|
||||
// Stop if destroyed
|
||||
isRunning
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue