I have a coroutine that listens asynchronously on an asio UDP socket. When it receives a message it co_spawns a new co-routine to handle the message and then goes back to listening on the port. This new coroutine may need to do additional communication on the same UDP socket. What is a good way to make sure the replies to the requests that the second coroutine makes comes back to it?
I was thinking of making some kind of future to store the reply that the new coroutine can co_await but it doesn't seem to be avaible in asio and it doesn't look to be easy to make. I could store a function object that get's called when a reply comes but then what's the point of coroutines in the first place? I could have the new coroutine listen to the same socket but which coroutine will then get the reply? Either? Both?
To summarize: I want to be able to suspend the new coroutine until I get a reply and when I do get a reply in the original coroutine I want it to resume the new coroutine. Basically I want something like cppcoro::single_consumer_event