Fixes more places where Android's coroutine cancellations might affect a mutex.

This commit is contained in:
Vitor Pamplona
2023-02-18 19:07:58 -05:00
parent 89f714b1ad
commit 2ac5174b78
2 changed files with 18 additions and 6 deletions
@@ -22,8 +22,10 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import nostr.postr.Contact
import nostr.postr.Persona
import nostr.postr.Utils
@@ -424,9 +426,14 @@ class Account(
handlerWaiting.set(true)
val scope = CoroutineScope(Job() + Dispatchers.Default)
scope.launch {
delay(100)
live.refresh()
handlerWaiting.set(false)
try {
delay(100)
live.refresh()
} finally {
withContext(NonCancellable) {
handlerWaiting.set(false)
}
}
}
}
@@ -298,9 +298,14 @@ class UserLiveData(val user: User): LiveData<UserState>(UserState(user)) {
handlerWaiting.set(true)
val scope = CoroutineScope(Job() + Dispatchers.Main)
scope.launch {
delay(100)
refresh()
handlerWaiting.set(false)
try {
delay(100)
refresh()
} finally {
withContext(NonCancellable) {
handlerWaiting.set(false)
}
}
}
}