• 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.basic09
7 
8 import kotlinx.coroutines.channels.*
9 import kotlinx.coroutines.*
10 import kotlin.coroutines.*
11 
<lambda>null12 fun main() = runBlocking<Unit> {
13     val broadcast = ConflatedBroadcastChannel<String>()
14     broadcast.offer("one")
15     broadcast.offer("two")
16     // now launch a coroutine to print the most recent update
17     launch { // use the context of the main thread for a coroutine
18         broadcast.consumeEach { println(it) }
19     }
20     broadcast.offer("three")
21     broadcast.offer("four")
22     yield() // yield the main thread to the launched coroutine
23     broadcast.close() // now close the broadcast channel to cancel the consumer, too
24 }
25