1 /* 2 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. 3 */ 4 5 package kotlinx.coroutines.reactive 6 7 import kotlinx.coroutines.channels.* 8 import org.reactivestreams.* 9 import kotlin.coroutines.* 10 11 /** 12 * Converts a stream of elements received from the channel to the hot reactive publisher. 13 * 14 * Every subscriber receives values from this channel in **fan-out** fashion. If the are multiple subscribers, 15 * they'll receive values in round-robin way. 16 * @param context -- the coroutine context from which the resulting observable is going to be signalled 17 */ 18 @Deprecated(message = "Deprecated in the favour of consumeAsFlow()", 19 level = DeprecationLevel.WARNING, // Error in 1.4 20 replaceWith = ReplaceWith("this.consumeAsFlow().asPublisher()")) <lambda>null21public fun <T> ReceiveChannel<T>.asPublisher(context: CoroutineContext = EmptyCoroutineContext): Publisher<T> = publish(context) { 22 for (t in this@asPublisher) 23 send(t) 24 } 25