dharrigan
08/11/2019, 12:15 PMfun doSomething() = GlobalScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
writeIntoTable1()
writeIntoTable2()
writeIntoTable3()
}
suspend fun writeIntoTable1() {...}
suspend fun writeIntoTable2() {...}
suspend fun writeIntoTable3() {...}
gildor
08/11/2019, 2:29 PMcoroutineScope {}
to group writes, so client could launch this suscpend function in own scope using launch, or just call suspend function (which is even better)
3. To make parallel version of this code less awkward I would use something like:
listOf(::writeIntoTable1, ::writeIntoTable2, ::writeIntoTable3).forEach { launch ( it() } }
Or any other way to group operations and do not copy paste invocation strategy
4. i see that you use IO dispatcher which looks suspicious in this case, because you call suspend function which itself never should block, so if write is blocking, just move this IO dispatcher to those functions or make them blocking explicitly, remove suspend modifier and add Blocking suffixdharrigan
08/11/2019, 3:51 PMDico
08/11/2019, 10:33 PMDico
08/11/2019, 10:33 PMgildor
08/12/2019, 3:50 AMwriteIntoTableN
is blocking better to remove suspend modifier which is probably useless and rather confusing for blocking function and rename it to writeIntoTableBlocking, so it will be clear that function is blocking and should be called from corresponding contextDico
08/12/2019, 9:38 AMDico
08/12/2019, 9:38 AM