blob: f3a4bf633537c8391336e8665dacd0e0bddb3195 [file] [log] [blame]
/*
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
// This file was automatically generated from coroutines-guide-reactive.md by Knit tool. Do not edit.
package kotlinx.coroutines.experimental.rx2.guide.basic08
import io.reactivex.subjects.*
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.rx2.*
import kotlin.coroutines.experimental.*
fun main(args: Array<String>) = runBlocking<Unit> {
val subject = BehaviorSubject.create<String>()
subject.onNext("one")
subject.onNext("two")
// now launch a coroutine to print the most recent update
launch(coroutineContext) { // use the context of the main thread for a coroutine
subject.consumeEach { println(it) }
}
subject.onNext("three")
subject.onNext("four")
yield() // yield the main thread to the launched coroutine <--- HERE
subject.onComplete() // now complete subject's sequence to cancel consumer, too
}