Revert "Fix thread starvation caused by not yielding or using an inappropriate thread pool (#2955)"

This reverts commit 22d5c9d9f4.
This commit is contained in:
AntsyLich
2026-03-20 15:28:29 +06:00
parent 56b70ef529
commit d3dcb7fe4b
16 changed files with 83 additions and 164 deletions
@@ -104,10 +104,10 @@ class DownloadManager(
return queueState.value.find { it.chapter.id == chapterId }
}
suspend fun startDownloadNow(chapterId: Long) {
fun startDownloadNow(chapterId: Long) {
val existingDownload = getQueuedDownloadOrNull(chapterId)
// If not in queue try to start a new download
val toAdd = existingDownload ?: Download.fromChapterId(chapterId) ?: return
val toAdd = existingDownload ?: runBlocking { Download.fromChapterId(chapterId) } ?: return
queueState.value.toMutableList().apply {
existingDownload?.let { remove(it) }
add(0, toAdd)
@@ -90,7 +90,7 @@ class DownloadStore(
/**
* Returns the list of downloads to restore. It should be called in a background thread.
*/
suspend fun restore(): List<Download> {
fun restore(): List<Download> {
val objs = preferences.all
.mapNotNull { it.value as? String }
.mapNotNull { deserialize(it) }
@@ -101,10 +101,10 @@ class DownloadStore(
val cachedManga = mutableMapOf<Long, Manga?>()
for ((mangaId, chapterId) in objs) {
val manga = cachedManga.getOrPut(mangaId) {
getManga.await(mangaId)
runBlocking { getManga.await(mangaId) }
} ?: continue
val source = sourceManager.get(manga.source) as? HttpSource ?: continue
val chapter = getChapter.await(chapterId) ?: continue
val chapter = runBlocking { getChapter.await(chapterId) } ?: continue
downloads.add(Download(source, manga, chapter))
}
}
@@ -111,9 +111,9 @@ class Downloader(
var isPaused: Boolean = false
init {
scope.launch {
val chapters = store.restore()
addAllToQueue(chapters)
launchNow {
val chapters = async { store.restore() }
addAllToQueue(chapters.await())
}
}