Which of these two approaches would be better? (an...
# coroutines
d
Which of these two approaches would be better? (and are they idomatic?)
m
Depends on what you need. #1 could have better performance if that's critical, otherwise #2 looks better
If you'd need to wait on writes to be completed to do some other work, you could just wrap single launch into a
coroutineScope {  }
and make
doSomething
suspending
Had a brain fart here,
coroutineScope {  }
would be more useful for #1
Also, try avoiding GlobalScope
I usually write it like this
Copy code
suspend fun doSomething() = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
    writeIntoTable1()
    writeIntoTable2()
    writeIntoTable3()
}
g
withContext(<http://Dispatchers.IO|Dispatchers.IO>)
is not needed if
writeIntoTableN
is suspend function