https://kotlinlang.org logo
Title
j

Jonathan

02/28/2018, 9:03 AM
Hi, is there an empty ReceiveChannel available in kotlinx.coroutines ?
e

elizarov

02/28/2018, 9:08 AM
No, but you can do
produce {}
. What is your use-case for it?
j

Jonathan

02/28/2018, 9:09 AM
Yes, I wrote
private val EmptyChannel = produce<Nothing> { }

fun <E> emptyChannel(): ReceiveChannel<E> = EmptyChannel
I just wondered if there was already something. thanks
e

elizarov

02/28/2018, 9:13 AM
Please consider filing an issue to https://github.com/Kotlin/kotlinx.coroutines/issues explaining your use-case. PR would be welcome, too.
j

Jonathan

02/28/2018, 1:31 PM
Basically we have the following interface:
interface MyInterface {
	fun openEventSubscription(): ReceiveChannel<Event>
}
Of course most implementations would delegate the subscription to a
BroadcastChannel
or use
produce
to create a channel. But, in some edges cases and in tests the implementation may simply want to return an empty channel Do you think it makes sense ? Should I submit an issue or a PR ?