Download from up to 5 different sources concurrently

This commit is contained in:
arkon 2020-05-08 18:41:27 -04:00 committed by Jay
parent f2fe1a7c23
commit 28cbbc3f14

View File

@ -197,14 +197,28 @@ class Downloader(
subscriptions.clear() subscriptions.clear()
subscriptions += downloadsRelay.concatMapIterable { it } subscriptions += downloadsRelay.concatMapIterable { it }
.concatMap { downloadChapter(it).subscribeOn(Schedulers.io()) }.onBackpressureBuffer() // Concurrently download from 5 different sources
.observeOn(AndroidSchedulers.mainThread()).subscribe({ .groupBy { it.source }
completeDownload(it) .flatMap(
}, { error -> { bySource ->
DownloadService.stop(context) bySource.concatMap { download ->
Timber.e(error) downloadChapter(download).subscribeOn(Schedulers.io())
notifier.onError(error.message) }
}) },
5
)
.onBackpressureBuffer()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
completeDownload(it)
},
{ error ->
DownloadService.stop(context)
Timber.e(error)
notifier.onError(error.message)
}
)
} }
/** /**