June 2018
Intermediate to advanced
310 pages
6h 32m
English
We could pass them the latch, of course. The latch, which we've already seen a couple of times, allows one thread to wait until the other threads have completed working:
private fun getName(latch: CountDownLatch) = launch { ... latch.countDown()}
But it's not a clear separation of concerns. Do we really want to specify how this function should be synchronized?
Let's have a second take:
private fun getName() = async { delay(Random().nextInt(100)) println("Got name") "Inigo Montoya"}private fun getCatchphrase() = async { delay(Random().nextInt(100)) println("Got catchphrase") "Hello. My name is Inigo Montoya. You killed my father. Prepare to die."}private fun getRepeats() = async { delay(Random().nextInt(100)) println("Got repeats" ...
Read now
Unlock full access