blob: 2529d5ba48b4a9d960b7814fe8672fa3998be10d [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.basic09
import kotlinx.coroutines.experimental.channels.*
import kotlinx.coroutines.experimental.*
import kotlin.coroutines.experimental.*
fun main(args: Array<String>) = runBlocking<Unit> {
val broadcast = ConflatedBroadcastChannel<String>()
broadcast.offer("one")
broadcast.offer("two")
// now launch a coroutine to print the most recent update
launch(coroutineContext) { // use the context of the main thread for a coroutine
broadcast.consumeEach { println(it) }
}
broadcast.offer("three")
broadcast.offer("four")
yield() // yield the main thread to the launched coroutine
broadcast.close() // now close broadcast channel to cancel consumer, too
}