Closed ecorm closed 2 years ago
Cover the use case on invoking RPCs within event handlers in the tutorial. One trick is to pass the CoroSession object to the event handler and spawn a coroutine from there using the executor bundled with Event:
CoroSession
Event
void onEvent(CoroSession<>::Ptr session, Event evt) { boost::asio::spawn(evt.executor(), [session](boost::asio::yield_context yield) { session->call(Rpc("Foo").withArgs(42), yield); }); }
The other way is to use basicCoroEvent or unpackedCoroEvent, which spawn a coroutine for the handler.
basicCoroEvent
unpackedCoroEvent
It turns out this is already in tutorial-pubsub.dox, under the heading Registering Coroutine Event Handlers.
tutorial-pubsub.dox
Cover the use case on invoking RPCs within event handlers in the tutorial. One trick is to pass the
CoroSession
object to the event handler and spawn a coroutine from there using the executor bundled withEvent
:The other way is to use
basicCoroEvent
orunpackedCoroEvent
, which spawn a coroutine for the handler.