Skip to content

Commit

Permalink
Delay callback to prevent blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Sep 8, 2023
1 parent a7a2a79 commit 3e2a365
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import be.mygod.vpnhotspot.net.IpNeighbour
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.collections.immutable.toPersistentMap
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.channels.onFailure
import kotlinx.coroutines.channels.trySendBlocking
import kotlinx.coroutines.launch

class IpNeighbourMonitor private constructor() : IpMonitor() {
companion object {
Expand All @@ -32,7 +37,7 @@ class IpNeighbourMonitor private constructor() : IpMonitor() {
monitor.flushAsync()
monitor.neighbours.values
}
}?.let { callback.onIpNeighbourAvailable(it) }
}?.let { GlobalScope.launch(Dispatchers.Main) { callback.onIpNeighbourAvailable(it) } }
fun unregisterCallback(callback: Callback) = synchronized(callbacks) {
if (callbacks.remove(callback) == null) return@synchronized
fullMode = callbacks.any { it.value }
Expand Down

0 comments on commit 3e2a365

Please sign in to comment.