rook
07/03/2019, 8:31 PMJob
join()
asynchronously? I’d like to append coroutines to a job dynamically and then have it complete when it runs out of running coroutinesbdawg.io
07/03/2019, 8:33 PMjoin
will continue to suspend (including if you spawn additional children)Dominaezzz
07/03/2019, 8:33 PMcoroutineScope
?Dominaezzz
07/03/2019, 8:34 PMJob
as a child of some other Job
?rook
07/03/2019, 8:44 PMval myJob = Job().apply{ invokeOnCompletion { /*some completion work*/ } }
val myContext = myJob + <http://Dispatchers.IO|Dispatchers.IO>
fun someWork() {
repo.dataStream.onEach {
launch(myContext) {
//do stuff
}
}
}
rook
07/03/2019, 8:45 PMstreetsofboston
07/03/2019, 8:46 PMcoroutineScope { ... }
, you make sure that that call to coroutineScope { ... }
resumes only after all its child Jobs have finishedstreetsofboston
07/03/2019, 8:53 PMval job = CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch {
coroutineScope {
repo.dataStream.onEach {
launch {
//do stuff
}
}
}
/*some completion work*/
}
job.invokeOnCompletion { /*some more completion work*/ }