June 2018
Intermediate to advanced
310 pages
6h 32m
English
Let's add another method to our Factory using the extension methods:
fun CoroutineFactory.longCoroutine(index: Int) = launch { var uuid = UUID.randomUUID() for (i in 1..100_000) { val newUuid = UUID.randomUUID() if (newUuid < uuid) { uuid = newUuid } if (i % 100 == 0) { yield() } } println("Done longCoroutine $index") latch.countDown()}
We call this method instead in the first loop:
...for (i in 1..10) { CoroutineFactory.longCoroutine(i)}...
And when we run it now, we get the output we expected in the first place:
Done shortCoroutine 0!Done shortCoroutine 1!Done shortCoroutine 2!Done shortCoroutine 3!Done shortCoroutine 5!Done shortCoroutine 6!Done shortCoroutine 7!Done shortCoroutine 8!Done shortCoroutine 9!Done shortCoroutine ...
Read now
Unlock full access