...

/

Solution: Channel and Actors

Solution: Channel and Actors

See the solution to the challenge on channels and actors.

We'll cover the following...

Solution

The solution to the challenge we just solved is as follows.

suspend fun main(): Unit = coroutineScope {
    val channel = produce(capacity = Channel.UNLIMITED) {
        repeat(3) { index ->
            send(index * 2)
            delay(200)
            println("Sent to channel")
        }
    }

    delay(1000)
    for (element in channel) {
        print("Received = ")
        println(element)
        delay(1000)
    }
}
Complete solution to the challenge

Here is a line–by–line ...