https://kotlinlang.org logo
Title
a

andyb

12/18/2017, 1:42 PM
Hi, just starting to ge my head around coroutines. Love them but have a question. I am using Channels as a queue between coroutines and would like to receive a message but timeout if no message appears within say 1 second. I am currently using
withTimeout(1000){ incoming.receive() }
to do this but it seems to be hanging rather than timing out. Am I missing something?
r

r4zzz4k

12/18/2017, 1:57 PM
Could you please post all of the code as a gist and put a link here? It's hard to say anything from just a receiver you've posted.
a

andyb

12/18/2017, 2:04 PM
Thanks, I have sorted it out I wasn't handling the
TimeoutCancellationException
properly
e

elizarov

12/18/2017, 2:52 PM
You can also use
withTimeoutOrNull
. Sometimes it is more convenient.
a

andyb

12/18/2017, 2:54 PM
Thanks, will have more of a thorough investigation later.