Daniel
07/12/2019, 7:07 PMclass Database {
fun prefillDatabase() {
// launch a non blocking job here that puts some data in the database
// image this is done on application start
}
suspend fun getEntities() {
// launch a blocking coroutine to get all entities of the database but only AFTER the job in prefillDatabase() completed
// imagine this is called later in the application on button click.
}
}
Is this a case for .join()? The job started in prefillDatabase() could already be well completed before getEntities() is calledstreetsofboston
07/12/2019, 7:11 PMDaniel
07/12/2019, 7:13 PMstreetsofboston
07/12/2019, 7:13 PMjoin
function is a suspend function.prefill
is called only once… other wise you’ll have a bit more work to do 🙂Daniel
07/12/2019, 7:15 PM* If the [Job] of the invoking coroutine is cancelled or completed when this
* suspending function is invoked or while it is suspended, this function
* throws [CancellationException].
But thats ok now I know what I have to try and where to look, a big thanks!octylFractal
07/12/2019, 8:27 PMgetEntities
coroutine is cancelled/completed, join
throws CancellationException
-- not if prefill
is completed.gildor
07/13/2019, 2:22 AM