Using C++20 coroutines to handle messages in agents
Hello! Have you considered using coroutines to process messages in agents? It would be good solution for waiting messages with saving context.
Something like that
class SomeAgent: public agent_t
{
// ...
coro_type sendRequestWaitResponse()
{
so_5::send<Request>(someMbox);
auto response = co_await so_5::receive<Response>(someMbox);
// handle response
}
//...
};
I tried to implement this in my application and found a solution, but I decided to abandon this idea because of one problem. When so_finish_agent is called, the agent can no longer receive messages, making it impossible to wait for all running coroutines to complete. Therefore, I concluded that if this should be implemented, it should be done at the library level.
Hi!
There is a couple of messages in Russian related to this topic:
https://www.linux.org.ru/forum/development/18146604?cid=18148015 https://www.linux.org.ru/forum/development/18146604?cid=18148025
In short: this topic is floating in the air and it seems it will be implemented somewhere in the future, but I can't say when.
Thank you for answer! Can I try to implement prototype and make PR? It would be great practice for me.
Can I try to implement prototype and make PR?
Of course, you can try, but I can't guarantee that it'll be accepted ;)
Ok, thanks. I just wanted to know that the PR would at least be reviewed)
I just wanted to know that the PR would at least be reviewed)
Of course it will.
Personally, I have no experience with C++20 coroutines yet. So if PR won't be accepted it will be useful to see how coroutines can be used in SObjectizer implementation.