July 2018
Intermediate to advanced
266 pages
7h 11m
English
Often, in order to guarantee that concurrent code is synchronized correctly, it's necessary to suspend or block execution while a task is completed in a different thread. But due to the complexity of these situations, it isn't uncommon to end up in a situation where the execution of the complete application is halted because of circular dependencies:
lateinit var jobA : Joblateinit var jobB : Jobfun main(args: Array<String>) = runBlocking { jobA = launch { delay(1000) // wait for JobB to finish jobB.join() } jobB = launch { // wait for JobA to finish jobA.join() } // wait for JobA to finish jobA.join() println("Finished")}
Let's take a look at a simple flow diagram of jobA.
In this example, jobA is waiting ...
Read now
Unlock full access