CppWAMP
C++11 client library for the WAMP protocol
|
The previous tutorials have used stackful routines to demonstrate CppWAMP. Traditional "callback" handler functions can also be used with wamp::Session.
For asynchronous operations that can fail, Session
expects a handler taking an wamp::ErrorOr<T> as a parameter. ErrorOr<T>
makes it difficult for handlers to ignore error conditions when accessing the result of an asynchronous operation via its value method.
The following example shows how to establish a connection using callback handler functions:
Instead of letting wamp::ErrorOr::get throw an exception upon failure, wamp::ErrorOr::operator bool() and wamp::ErrorOr::errorCode can be used to check the error status of an asynchronous operation:
The following example shows how to call member functions within asynchronous handlers, and how to chain one asynchronous operation after another:
With this asynchronous style of programming, it is not immediately obvious how the program control flows. Couroutines are therefore useful in implementing asynchronous logic in a more synchronous, sequential manner.
For complete examples using the asynchronous API see:
Next: User Type Conversions