• 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.basic08
7 
8 import io.reactivex.subjects.*
9 import kotlinx.coroutines.*
10 import kotlinx.coroutines.rx2.*
11 import kotlin.coroutines.*
12 
<lambda>null13 fun main() = runBlocking<Unit> {
14     val subject = BehaviorSubject.create<String>()
15     subject.onNext("one")
16     subject.onNext("two")
17     // now launch a coroutine to print the most recent update
18     launch { // use the context of the main thread for a coroutine
19         subject.collect { println(it) }
20     }
21     subject.onNext("three")
22     subject.onNext("four")
23     yield() // yield the main thread to the launched coroutine <--- HERE
24     subject.onComplete() // now complete the subject's sequence to cancel the consumer, too
25 }
26