|
Robot Raconteur Core C++ Library
|
Adapter for asynchronous operations for use with IOContextThreadPool. More...
#include <ThreadPool.h>
Public Member Functions | |
| IOContextThreadPool_AsyncResultAdapter (boost::shared_ptr< RobotRaconteurNode > &node, boost::asio::io_context &io_context) | |
| Construct an IOContextThreadPool_AsyncResultAdapter. | |
| IOContextThreadPool_AsyncResultAdapter (boost::asio::io_context &io_context) | |
| Construct an IOContextThreadPool_AsyncResultAdapter for the singleton RobotRaconteurNode. | |
| result_type | GetResult () |
| Get the result of the asynchronous operation. | |
| bool | PollResult (result_type &ret, boost::shared_ptr< RobotRaconteurException > &exp) |
| Polls for a result, nonblocking. | |
Adapter for asynchronous operations for use with IOContextThreadPool.
See threading for more information.
Asynchronous functions require a handler function be specified to be invoked when the operation is complete. The IOContextThreadPool_AsyncResultAdapter (result adapter) is a utility class for single threaded applications to simplify the design of calling asynchronous functions. The result adapter is passed the current boost::asio::io_context, and the asynchronous function is invoked with the result adapter passed as the handler. Next, GetResult() is called. This function will block until the result is available, or an error occurs. GetResult() will repeatedly call boost::asio::io_context::run_one() while waiting for the result to be ready. This will run the thread pool, allowing events to be dispatched while waiting for the result. This design removes the need for chained callbacks.
Must only be used in single-threaded applications
| T | The return type, or void if no return |
|
inline |
Construct an IOContextThreadPool_AsyncResultAdapter.
Should be constructed on the stack
| node | The node that will use the adapter |
| io_context | The single threaded IO Context |
|
inline |
Construct an IOContextThreadPool_AsyncResultAdapter for the singleton RobotRaconteurNode.
Should be constructed on the stack
| io_context | The single threaded IO Context |
|
inline |
Get the result of the asynchronous operation.
Will throw an exception if the operation fails, or the operation returns an exception.
Will block until the result is available or an error occurs. boost::asio::io_context::run() is called while waiting to continue dispatching events.
|
inline |
Polls for a result, nonblocking.
Nonblocking poll operation to check if results are ready, and retrieve the result. Does not call any functions in boost::asio::io_context. User must call boost::asio::io_context::poll() to dispatch waiting events. PollResult() will not throw an exception if an error occurs, instead it will fill the exp reference parameter.
| ret | [out] The result of the operation, valid if return is true |
| exp | [out] The exception returned by operation, or NULL if no exception, valid if return is true |