tseisel
11/27/2019, 1:09 PMReceiveChannel<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:
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 ?elizarov
11/27/2019, 5:13 PM