https://kotlinlang.org logo
#coroutines
Title
# coroutines
z

zeugederunity

06/30/2021, 1:07 PM
Hello everyone, when calling ReceiveChannel<T>::receiveCatching i get an object of type ChannelResult<ChannelResult<T>> back. But when i call ReceiveChannel<T>::receive i get an object of type T. Is this a bug or did i miss something in the API? Thanks in advance!
d

diesieben07

06/30/2021, 2:19 PM
receive
will throw an exception if the channel is closed.
receiveCatching
doesn't throw, it returns you a failed
ChannelResult
instead.
z

zeugederunity

06/30/2021, 4:15 PM
Yes, but as far as i understood the documentation of receiveCatching it should return a ChannelResult<T>, not a ChannelResult<ChannelResult<T>>
d

diesieben07

06/30/2021, 4:20 PM
Oops, I completely skipped that part of your question... Yes it should not do that as far as I can tell
e

efemoney

06/30/2021, 5:02 PM
Can you post the body of the particular function (plus context)? I used those apis and cannot see the same issue
j

Justin

06/30/2021, 11:37 PM
If you make heavy use of smart casting and generics, you may have accidentally specified a generic type to be
ChannelResult<T>
instead of
T
. Create a temporary variable
val tempVariable = {yourChannelVariable}
and set it to the channel in question, then have the IDE add the explicit type. It’s likely that your channel’s type is
ChannelResult<T>
and not
T
z

zeugederunity

07/01/2021, 8:33 AM
After testing around i decided to make a bugreport. This behaviour just occurs with JVM, but on with JS.
2 Views