File tree Expand file tree Collapse file tree 2 files changed +4
-6
lines changed
kotlinx-coroutines-core/src/test/kotlin/guide Expand file tree Collapse file tree 2 files changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -1351,10 +1351,9 @@ received number:
1351
1351
1352
1352
``` kotlin
1353
1353
fun launchProcessor (id : Int , channel : ReceiveChannel <Int >) = launch(CommonPool ) {
1354
- while (true ) {
1355
- val x = channel.receive()
1354
+ for (x in channel) {
1356
1355
println (" Processor #$id received $x " )
1357
- }
1356
+ }
1358
1357
}
1359
1358
```
1360
1359
Original file line number Diff line number Diff line change @@ -29,10 +29,9 @@ fun produceNumbers() = produce<Int>(CommonPool) {
29
29
}
30
30
31
31
fun launchProcessor (id : Int , channel : ReceiveChannel <Int >) = launch(CommonPool ) {
32
- while (true ) {
33
- val x = channel.receive()
32
+ for (x in channel) {
34
33
println (" Processor #$id received $x " )
35
- }
34
+ }
36
35
}
37
36
38
37
fun main (args : Array <String >) = runBlocking<Unit > {
You can’t perform that action at this time.
0 commit comments