ecorm/cppwamp

Cover invoking RPCs within event handlers in tutorials

ecorm opened this issue · 1 comments

ecorm commented

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:

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.

ecorm commented

It turns out this is already in tutorial-pubsub.dox, under the heading Registering Coroutine Event Handlers.