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.basic03 7 8 import io.reactivex.* 9 import kotlinx.coroutines.* 10 import kotlinx.coroutines.channels.* 11 import kotlinx.coroutines.reactive.* 12 <lambda>null13fun main() = runBlocking<Unit> { 14 val source = Flowable.range(1, 5) // a range of five numbers 15 .doOnSubscribe { println("OnSubscribe") } // provide some insight 16 .doOnComplete { println("OnComplete") } // ... 17 .doFinally { println("Finally") } // ... into what's going on 18 var cnt = 0 19 source.openSubscription().consume { // open channel to the source 20 for (x in this) { // iterate over the channel to receive elements from it 21 println(x) 22 if (++cnt >= 3) break // break when 3 elements are printed 23 } 24 // Note: `consume` cancels the channel when this block of code is complete 25 } 26 } 27