Skip to content

Commit 7a96030

Browse files
committed
improved backoff stragegy
1 parent d60281c commit 7a96030

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

fetch2/src/main/java/com/tonyodev/fetch2/helper/PriorityListProcessorImpl.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class PriorityListProcessorImpl constructor(private val handlerWrapper: HandlerW
6161
increaseBackOffTime()
6262
}
6363
delegate?.onHasActiveDownloads(priorityList.isNotEmpty())
64+
var shouldBackOff = true
6465
for (index in 0..priorityList.lastIndex) {
6566
if (downloadManager.canAccommodateNewDownload() && canContinueToProcess()) {
6667
val download = priorityList[index]
@@ -75,9 +76,11 @@ class PriorityListProcessorImpl constructor(private val handlerWrapper: HandlerW
7576
if (!properNetworkConditions) {
7677
listenerCoordinator.mainListener.onWaitingNetwork(download)
7778
}
78-
if ((isFetchServerRequest || properNetworkConditions) && !downloadManager.contains(download.id)
79-
&& canContinueToProcess()) {
80-
downloadManager.start(download)
79+
if ((isFetchServerRequest || properNetworkConditions)) {
80+
shouldBackOff = false
81+
if (!downloadManager.contains(download.id) && canContinueToProcess()) {
82+
downloadManager.start(download)
83+
}
8184
}
8285
} else {
8386
break
@@ -86,6 +89,9 @@ class PriorityListProcessorImpl constructor(private val handlerWrapper: HandlerW
8689
break
8790
}
8891
}
92+
if (shouldBackOff) {
93+
increaseBackOffTime()
94+
}
8995
}
9096
registerPriorityIterator()
9197
}

0 commit comments

Comments
 (0)