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,11 +426,16 @@ class Account(
handlerWaiting.set(true)
val scope = CoroutineScope(Job() + Dispatchers.Default)
scope.launch {
try {
delay(100)
live.refresh()
} finally {
withContext(NonCancellable) {
handlerWaiting.set(false)
}
}
}
}
fun isHidden(user: User) = user in hiddenUsers()
@@ -298,11 +298,16 @@ class UserLiveData(val user: User): LiveData<UserState>(UserState(user)) {
handlerWaiting.set(true)
val scope = CoroutineScope(Job() + Dispatchers.Main)
scope.launch {
try {
delay(100)
refresh()
} finally {
withContext(NonCancellable) {
handlerWaiting.set(false)
}
}
}
}
private fun refresh() {
postValue(UserState(user))