Use flatMap with a limit instead of windows for concurrent downloads

This commit is contained in:
inorichi 2015-11-04 19:54:01 +01:00
parent 999cc0df6e
commit 3bdca95d96

View file

@ -68,9 +68,7 @@ public class DownloadManager {
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.filter(event -> !isChapterDownloaded(event)) .filter(event -> !isChapterDownloaded(event))
.flatMap(this::createDownload) .flatMap(this::createDownload)
.window(preferences.getDownloadThreads()) .flatMap(this::downloadChapter, preferences.getDownloadThreads())
.concatMap(concurrentDownloads -> concurrentDownloads
.concatMap(this::downloadChapter))
.onBackpressureBuffer() .onBackpressureBuffer()
.subscribe(); .subscribe();
} }
@ -131,7 +129,7 @@ public class DownloadManager {
download.source.getRemainingImageUrlsFromPageList(pageList))) download.source.getRemainingImageUrlsFromPageList(pageList)))
// Start downloading images, consider we can have downloaded images already // Start downloading images, consider we can have downloaded images already
.concatMap(page -> getDownloadedImage(page, download.source, download.directory)) .concatMap(page -> getDownloadedImage(page, download.source, download.directory))
// Remove from the queue // Do after download completes
.doOnCompleted(() -> onChapterDownloaded(download)); .doOnCompleted(() -> onChapterDownloaded(download));
} }