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 += downloadsRelay.concatMapIterable { it }
.concatMap { downloadChapter(it).subscribeOn(Schedulers.io()) }.onBackpressureBuffer()
.observeOn(AndroidSchedulers.mainThread()).subscribe({
completeDownload(it)
}, { error ->
DownloadService.stop(context)
Timber.e(error)
notifier.onError(error.message)
})
// Concurrently download from 5 different sources
.groupBy { it.source }
.flatMap(
{ bySource ->
bySource.concatMap { download ->
downloadChapter(download).subscribeOn(Schedulers.io())
}
},
5
)
.onBackpressureBuffer()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
completeDownload(it)
},
{ error ->
DownloadService.stop(context)
Timber.e(error)
notifier.onError(error.message)
}
)
}
/**