Skip to content

Commit a261826

Browse files
authored
Merge pull request #89 from what3words/fix/concurrent-modification-exception-when-adding-marker
Fix ConcurrentModificationException in addMarker method
2 parents d8d30b8 + 03fa01d commit a261826

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

  • lib-compose/src/main/java/com/what3words/components/compose/maps

lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapManager.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,19 +1475,21 @@ class W3WMapManager(
14751475
listName: String = LIST_DEFAULT_ID,
14761476
zoomOption: W3WZoomOption = W3WZoomOption.CENTER_AND_ZOOM,
14771477
): List<W3WResult<W3WMarker>> = withContext(dispatcher) {
1478-
val results = inputs.map { input ->
1478+
val conversionResults = inputs.map { input ->
14791479
async {
1480-
// Convert and add marker
1481-
when (val result = convertFunction(input)) {
1482-
is W3WResult.Success -> {
1483-
val marker = result.value.toW3WMarker(markerColor)
1484-
markersMap.addMarker(listName = listName, marker = marker)
1485-
}
1480+
convertFunction(input)
1481+
}
1482+
}.awaitAll()
14861483

1487-
is W3WResult.Failure -> W3WResult.Failure(result.error, result.message)
1484+
val results = conversionResults.map { result ->
1485+
when (result) {
1486+
is W3WResult.Success -> {
1487+
val marker = result.value.toW3WMarker(markerColor)
1488+
markersMap.addMarker(listName = listName, marker = marker)
14881489
}
1490+
is W3WResult.Failure -> W3WResult.Failure(result.error, result.message)
14891491
}
1490-
}.awaitAll()
1492+
}
14911493

14921494
// Update the map state
14931495
_mapState.update { currentState ->

0 commit comments

Comments
 (0)