ecorm / cppwamp

C++ client library for the WAMP protocol.
Boost Software License 1.0
35 stars 9 forks source link

Cover invoking RPCs within event handlers in tutorials #90

Closed ecorm closed 2 years ago

ecorm commented 8 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:

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 2 years ago

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