the.bay.news

Modifying a var within an async coroutine

Kotlin Discussions
Modifying a var within an async coroutine
I’ve inherited some code and I’m wondering about how thread-safe it is. What’s bugging me is that the code makes an assignment to a var from within code that could be executed on any number of threads. Here’s the idea: data class Stuff(val number: Int) data class Thing(val accumulation: Int) suspend fun foo(): Int { var count: Thing = Thing(0) val listOfStuff = listOf<Stuff>(/* a bunch of Stuffs here */) coroutineScope { listOfStuff.map { s -> async { ...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.