Since `ReceiveChannel<T>.onReceiveOrNull` ha...
# coroutines
t
Since
ReceiveChannel<T>.onReceiveOrNull
has been deprecated, it is suggested to replace it with the
onReceiveOrNull
extension function. But I find that it's surprisingly hard to use that function: 1. Since there is a member property
onReceiveOrNull
it takes precedence over the extension. 2. Since
onReceiveOrNull
is a function, the block passed as select clause is incorrectly interpreted as an extra lambda parameter. While the following workaround code works:
Copy code
import kotlinx.coroutines.channels.onReceiveOrNull as onReceiveOrNullExt

select {
    channel.onReceiveOrNullExt().invoke { foo ->
        [...]
    }

    anotherChannel.onReceive { bar ->
        [...]
    }
}
It is not as convenient as the original Select API. Wouldn't it be better to convert that extension function to an extension property with a different name ?
e
Thank for feedback. I’ve filed it here: https://github.com/Kotlin/kotlinx.coroutines/issues/1676