I have a SharedFlow which outputs frames decoded f...
# coroutines
l
I have a SharedFlow which outputs frames decoded from a socket. One of the steps I am required to do is send a handshake, and then I should get one back. I confirm that this is indeed getting passed to the flow and I can even retrieve it using the following piece of code
Copy code
incoming.filterIsInstance<WampRawTransportPacket.Handshake>().first()
however, I also want to have a timeout around it as to not hang forever if the remote server does something weird. So I used the withTimeoutOrNull function, but I encounter some odd behavior.
Copy code
withTimeoutOrNull(connectionConfig.handshakeTimeout) {
    incoming.filterIsInstance<WampRawTransportPacket.Handshake>().first()
} ?: throw WampTimeout(
    remoteAddress,
    "Timed out waiting ${connectionConfig.handshakeTimeout}ms for a handshake back!"
)
It will always time out after 5 seconds (that is what handshakeTimeout is currently configured at). If I take it out of the timeout, it works flawlessly and returns nearly instantly. Is there some side effect of the coroutine that timeout provides that I don't know about?
seems like the function calling this may end up being apart of a runBlocking scope... and i suppose the timeout blocks the execution in a way.