Add syncronized to PageLoader.tasks (fix crash)

This commit is contained in:
Koitharu
2022-11-03 17:57:18 +02:00
parent 5a43e677c5
commit 4665f8b74e

View File

@@ -66,7 +66,9 @@ class PageLoader @Inject constructor(
override fun close() { override fun close() {
loaderScope.cancel() loaderScope.cancel()
tasks.clear() synchronized(tasks) {
tasks.clear()
}
} }
fun isPrefetchApplicable(): Boolean { fun isPrefetchApplicable(): Boolean {
@@ -103,7 +105,9 @@ class PageLoader @Inject constructor(
return task return task
} }
task = loadPageAsyncImpl(page) task = loadPageAsyncImpl(page)
tasks[page.id] = task synchronized(tasks) {
tasks[page.id] = task
}
return task return task
} }
@@ -135,7 +139,9 @@ class PageLoader @Inject constructor(
while (prefetchQueue.isNotEmpty()) { while (prefetchQueue.isNotEmpty()) {
val page = prefetchQueue.pollFirst() ?: return val page = prefetchQueue.pollFirst() ?: return
if (cache[page.url] == null) { if (cache[page.url] == null) {
tasks[page.id] = loadPageAsyncImpl(page) synchronized(tasks) {
tasks[page.id] = loadPageAsyncImpl(page)
}
return return
} }
} }