is there any better option than Collections.synchr...
# coroutines
n
is there any better option than Collections.synchronizedList(mutableListOf()) in stdlib or in libraries ? i would feel a lot safer if i knew that i do not have any nasty ConcurrentCoModificationExceptions waiting for me due to forgetting to synchronize() on the list somewhere
g
what is your use case for this? Usually with coroutines you can replace such mutable structure with actor that allows synchronise operations to mutable state or use some another approach
b
@Nikky You might find
CopyOnWriteArrayList
Useful. But it is costly if you are doing a lot of mutations.
n
Well.. I am iterating over, filtering, calling contains and adding to a MutableList<String> I know how to use channels to synchronize adding.. I am not too sure about the rest
g
You can use actors, it allows you to encapsulate state and safely update it (actor by default process commands sequentially)