From 515308dc3d5fe0624f235cb9fd84358e7e59b7a1 Mon Sep 17 00:00:00 2001 From: Victoria Petrakovich <78360457+PetrakovichVictoria@users.noreply.github.com> Date: Tue, 16 Apr 2024 10:06:25 +0200 Subject: [PATCH] fix: get rid of horizontal scrolling by splitting the comment and show more code mentioned (#4100) --- docs/topics/channels.md | 5 +++-- kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) 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!") diff --git a/kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt b/kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt index d68c113bd2..8c9845afa5 100644 --- a/kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt +++ b/kotlinx-coroutines-core/jvm/test/guide/example-channel-01.kt @@ -7,7 +7,8 @@ import kotlinx.coroutines.channels.* fun main() = runBlocking { 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: