Perform callback without holding lock

This commit is contained in:
Mygod
2020-07-28 04:33:49 +08:00
parent f226eb8a05
commit f60658a2d8

View File

@@ -48,7 +48,9 @@ class IpNeighbourMonitor private constructor() : IpMonitor() {
private val aggregator = GlobalScope.actor<PersistentMap<IpDev, IpNeighbour>>(capacity = Channel.CONFLATED) {
for (value in channel) {
val neighbours = value.values
synchronized(callbacks) { for ((callback, _) in callbacks) callback.onIpNeighbourAvailable(neighbours) }
for (callback in synchronized(callbacks) { callbacks.keys.toList() }) {
callback.onIpNeighbourAvailable(neighbours)
}
}
}
private var neighbours = persistentMapOf<IpDev, IpNeighbour>()