June 2018
Intermediate to advanced
316 pages
6h 34m
English
We can create our own suspendingSequence function using an example from GitHub (https://github.com/Kotlin/kotlin-coroutines/blob/master/examples/suspendingSequence/suspendingSequence.kt). This function creates a sequence that can run suspending functions and lambdas.
The suspendingSequence function can be used as follows:
suspend fun coroutinesSuspendingSequenceOrder(amountOfCakes: Int) = suspendingSequence { (0 until amountOfCakes) .map { async { Baker().bake() } } .forEach { yield(it.await()) }}.iterator().toList()
In the preceding snippet, the coroutineSuspendingSequenceOrder function contains a range from 0 to amountOfCakes. We map each value from the range to an instance of the Deferred class using the ...
Read now
Unlock full access