diff --git a/docs/topics/channels.md b/docs/topics/channels.md index 3b8b11fbbe..019dae8476 100644 --- a/docs/topics/channels.md +++ b/docs/topics/channels.md @@ -19,7 +19,8 @@ fun main() = runBlocking { //sampleStart val channel = Channel() launch { - // this might be heavy CPU-consuming computation or async logic, we'll just send five squares + // this might be heavy CPU-consuming computation or async logic, + // we'll just send five squares for (x in 1..5) channel.send(x * x) } // here we print five received integers: @@ -103,12 +104,12 @@ and an extension function [consumeEach], that replaces a `for` loop on the consu import kotlinx.coroutines.* import kotlinx.coroutines.channels.* +//sampleStart fun CoroutineScope.produceSquares(): ReceiveChannel = produce { for (x in 1..5) send(x * x) } fun main() = runBlocking { -//sampleStart val squares = produceSquares() squares.consumeEach { println(it) } println("Done!")