Hi, just starting to ge my head around coroutines....
# coroutines
a
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
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
Thanks, I have sorted it out I wasn't handling the
TimeoutCancellationException
properly
e
You can also use
withTimeoutOrNull
. Sometimes it is more convenient.
a
Thanks, will have more of a thorough investigation later.