mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-29 21:52:31 +02:00
Correctly handling Atomic Boolean
This commit is contained in:
@@ -13,6 +13,7 @@ import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
|
|||||||
import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.ReactionEvent
|
import com.vitorpamplona.amethyst.service.model.ReactionEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
import com.vitorpamplona.amethyst.service.model.RepostEvent
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@@ -99,19 +100,18 @@ class CardFeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var handlerWaiting = AtomicBoolean()
|
||||||
|
|
||||||
var handlerWaiting = false
|
@Synchronized
|
||||||
fun invalidateData() {
|
private fun invalidateData() {
|
||||||
synchronized(handlerWaiting) {
|
if (handlerWaiting.getAndSet(true)) return
|
||||||
if (handlerWaiting) return
|
|
||||||
|
|
||||||
handlerWaiting = true
|
handlerWaiting.set(true)
|
||||||
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||||
scope.launch {
|
scope.launch {
|
||||||
delay(100)
|
delay(100)
|
||||||
refresh()
|
refresh()
|
||||||
handlerWaiting = false
|
handlerWaiting.set(false)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -117,7 +117,7 @@ abstract class FeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel()
|
|||||||
private var handlerWaiting = AtomicBoolean()
|
private var handlerWaiting = AtomicBoolean()
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun invalidateData() {
|
private fun invalidateData() {
|
||||||
if (handlerWaiting.get()) return
|
if (handlerWaiting.getAndSet(true)) return
|
||||||
|
|
||||||
handlerWaiting.set(true)
|
handlerWaiting.set(true)
|
||||||
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||||
|
@@ -81,7 +81,7 @@ open class UserFeedViewModel(val dataSource: NostrDataSource<User>): ViewModel()
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun invalidateData() {
|
private fun invalidateData() {
|
||||||
if (handlerWaiting.get()) return
|
if (handlerWaiting.getAndSet(true)) return
|
||||||
|
|
||||||
handlerWaiting.set(true)
|
handlerWaiting.set(true)
|
||||||
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||||
|
Reference in New Issue
Block a user