From f60658a2d8cec918504921fa5727fbd65f10d933 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 28 Jul 2020 04:33:49 +0800 Subject: [PATCH] Perform callback without holding lock --- .../be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt index 32554d2f..3ab992ff 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt @@ -48,7 +48,9 @@ class IpNeighbourMonitor private constructor() : IpMonitor() { private val aggregator = GlobalScope.actor>(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()