i'm experimenting with Kotlin coroutines.
say i have a mutable list:
val list = mutableListOf<String>()
and i launched 50 couroutines like this:
runBlocking {
for (i in 1..50) {
launch(Dispatchers.IO) {
delay(1000)
list.add(i.toString())
}
}
}
list.forEach { println(it) }
obviously the operations will take about one second despite the "delay(1000)" since they're running asynchronously
those were simple operations that won't cause a problem, but what if i'm writing a lot of big strings at the same time, would some of the operations fail ?
what about writing to a local file using appendText function, would some of the operations fail because the file might be locked by another writing operation ?