fix crash if cancel migration too soon

This commit is contained in:
Cuong-Tran 2024-10-29 16:59:37 +07:00
parent 55906548ee
commit dd0c3a516e
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
2 changed files with 4 additions and 3 deletions

View file

@ -22,7 +22,7 @@ class MigratingManga(
val migrationScope = CoroutineScope(parentContext + SupervisorJob() + Dispatchers.Default)
// KMK -->
lateinit var searchingJob: Deferred<Manga?>
var searchingJob: Deferred<Manga?>? = null
// KMK <--
val searchResult = MutableStateFlow<SearchResult>(SearchResult.Searching)

View file

@ -296,7 +296,7 @@ class MigrationListScreenModel(
}
}
// KMK -->
manga.searchingJob.await()
manga.searchingJob?.await()
// KMK <--
} catch (e: CancellationException) {
// Ignore canceled migrations
@ -571,7 +571,8 @@ class MigrationListScreenModel(
screenModelScope.launchIO {
val item = migratingItems.value.orEmpty().find { it.manga.id == mangaId }
?: return@launchIO
item.searchingJob.cancel()
item.searchingJob?.cancel()
item.searchingJob = null
item.searchResult.value = SearchResult.NotFound
sourceFinished()
}