Skip to content

Commit ec9384c

Browse files
committed
Fixed "Fan-out" example using iteration to receive from channel
1 parent bff3f37 commit ec9384c

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

coroutines-guide.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,10 +1351,9 @@ received number:
13511351

13521352
```kotlin
13531353
fun launchProcessor(id: Int, channel: ReceiveChannel<Int>) = launch(CommonPool) {
1354-
while (true) {
1355-
val x = channel.receive()
1354+
for (x in channel) {
13561355
println("Processor #$id received $x")
1357-
}
1356+
}
13581357
}
13591358
```
13601359

kotlinx-coroutines-core/src/test/kotlin/guide/example-channel-06.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ fun produceNumbers() = produce<Int>(CommonPool) {
2929
}
3030

3131
fun launchProcessor(id: Int, channel: ReceiveChannel<Int>) = launch(CommonPool) {
32-
while (true) {
33-
val x = channel.receive()
32+
for (x in channel) {
3433
println("Processor #$id received $x")
35-
}
34+
}
3635
}
3736

3837
fun main(args: Array<String>) = runBlocking<Unit> {

0 commit comments

Comments
 (0)