• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 // This file was automatically generated from coroutines-guide-reactive.md by Knit tool. Do not edit.
6 package kotlinx.coroutines.rx2.guide.basic01
7 
8 import kotlinx.coroutines.*
9 import kotlinx.coroutines.channels.*
10 import kotlin.coroutines.*
11 
<lambda>null12 fun main() = runBlocking<Unit> {
13     // create a channel that produces numbers from 1 to 3 with 200ms delays between them
14     val source = produce<Int> {
15         println("Begin") // mark the beginning of this coroutine in output
16         for (x in 1..3) {
17             delay(200) // wait for 200ms
18             send(x) // send number x to the channel
19         }
20     }
21     // print elements from the source
22     println("Elements:")
23     source.consumeEach { // consume elements from it
24         println(it)
25     }
26     // print elements from the source AGAIN
27     println("Again:")
28     source.consumeEach { // consume elements from it
29         println(it)
30     }
31 }
32