Hi, is there an empty ReceiveChannel available in ...
# coroutines
j
Hi, is there an empty ReceiveChannel available in kotlinx.coroutines ?
e
No, but you can do
produce {}
. What is your use-case for it?
j
Yes, I wrote
Copy code
private val EmptyChannel = produce<Nothing> { }

fun <E> emptyChannel(): ReceiveChannel<E> = EmptyChannel
I just wondered if there was already something. thanks
e
Please consider filing an issue to https://github.com/Kotlin/kotlinx.coroutines/issues explaining your use-case. PR would be welcome, too.
j
Basically we have the following interface:
Copy code
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 ?