Copy lists/maps when iterating to avoid concurrent exceptions
This commit is contained in:
parent
c581564bb1
commit
d3fb12da19
@ -129,7 +129,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
|||||||
Timber.i("### LocationSharingService.onLocationUpdate. Uncertainty: ${locationData.uncertainty}")
|
Timber.i("### LocationSharingService.onLocationUpdate. Uncertainty: ${locationData.uncertainty}")
|
||||||
|
|
||||||
// Emit location update to all rooms in which live location sharing is active
|
// Emit location update to all rooms in which live location sharing is active
|
||||||
roomArgsMap.forEach { item ->
|
roomArgsMap.toMap().forEach { item ->
|
||||||
sendLiveLocation(item.value.roomId, item.key, locationData)
|
sendLiveLocation(item.value.roomId, item.key, locationData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ class LocationSharingService : VectorService(), LocationTracker.Callback {
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun removeRoomArgs(roomId: String) {
|
private fun removeRoomArgs(roomId: String) {
|
||||||
roomArgsMap
|
roomArgsMap.toMap()
|
||||||
.filter { it.value.roomId == roomId }
|
.filter { it.value.roomId == roomId }
|
||||||
.forEach { roomArgsMap.remove(it.key) }
|
.forEach { roomArgsMap.remove(it.key) }
|
||||||
}
|
}
|
||||||
|
@ -83,10 +83,10 @@ class LocationSharingServiceConnection @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onCallbackActionNoArg(action: Callback.() -> Unit) {
|
private fun onCallbackActionNoArg(action: Callback.() -> Unit) {
|
||||||
callbacks.forEach(action)
|
callbacks.toList().forEach(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun forwardErrorToCallbacks(error: Throwable) {
|
private fun forwardErrorToCallbacks(error: Throwable) {
|
||||||
callbacks.forEach { it.onLocationServiceError(error) }
|
callbacks.toList().forEach { it.onLocationServiceError(error) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ class LocationTracker @Inject constructor(
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun onNoLocationProviderAvailable() {
|
private fun onNoLocationProviderAvailable() {
|
||||||
callbacks.forEach {
|
callbacks.toList().forEach {
|
||||||
try {
|
try {
|
||||||
it.onNoLocationProviderAvailable()
|
it.onNoLocationProviderAvailable()
|
||||||
} catch (error: Exception) {
|
} catch (error: Exception) {
|
||||||
@ -228,7 +228,7 @@ class LocationTracker @Inject constructor(
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun onLocationUpdate(locationData: LocationData) {
|
private fun onLocationUpdate(locationData: LocationData) {
|
||||||
callbacks.forEach {
|
callbacks.toList().forEach {
|
||||||
try {
|
try {
|
||||||
it.onLocationUpdate(locationData)
|
it.onLocationUpdate(locationData)
|
||||||
} catch (error: Exception) {
|
} catch (error: Exception) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user