https://kotlinlang.org logo
Title
d

digitalsanctum

01/03/2019, 11:53 PM
What would be a better way of doing the following:
listOf(
  CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch { ddbTools.deleteTableInRegions(destinationTable, destinationRegions) },
  CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch { jobService.deleteJobTable() },
  CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch { jobService.deleteCheckpointTable() }).joinAll()
l

louiscad

01/04/2019, 12:02 AM
@digitalsanctum
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
    launch { … }
    launch { … }
    launch { … }
} //No need for joinAll() thanks to structured concurrency
👍 2
d

digitalsanctum

01/04/2019, 12:03 AM
okay, great. thanks!
@louiscad follow-up question: how best to structure things around one launch depending on another?
l

louiscad

01/04/2019, 12:55 AM
@digitalsanctum Don't launch in that case. Just execute code sequentially.
d

digitalsanctum

01/04/2019, 12:56 AM
so just let the fact that it will block without launch dictate that it needs to finish before continuing with launches
l

louiscad

01/04/2019, 12:57 AM
I'm not sure I understand your sentence