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.basic02 7 8 import kotlinx.coroutines.* 9 import kotlinx.coroutines.reactive.* 10 import kotlin.coroutines.* 11 <lambda>null12fun main() = runBlocking<Unit> { 13 // create a publisher that produces numbers from 1 to 3 with 200ms delays between them 14 val source = publish<Int> { 15 // ^^^^^^^ <--- Difference from the previous examples is here 16 println("Begin") // mark the beginning of this coroutine in output 17 for (x in 1..3) { 18 delay(200) // wait for 200ms 19 send(x) // send number x to the channel 20 } 21 } 22 // print elements from the source 23 println("Elements:") 24 source.collect { // collect elements from it 25 println(it) 26 } 27 // print elements from the source AGAIN 28 println("Again:") 29 source.collect { // collect elements from it 30 println(it) 31 } 32 } 33