Robot Raconteur Core C++ Library
Loading...
Searching...
No Matches
RobotRaconteur::IOContextThreadPool_AsyncResultAdapter< T > Class Template Reference

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.

Detailed Description

template<typename T>
class RobotRaconteur::IOContextThreadPool_AsyncResultAdapter< T >

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

Template Parameters
TThe return type, or void if no return

Constructor & Destructor Documentation

◆ IOContextThreadPool_AsyncResultAdapter() [1/2]

template<typename T>
RobotRaconteur::IOContextThreadPool_AsyncResultAdapter< T >::IOContextThreadPool_AsyncResultAdapter ( boost::shared_ptr< RobotRaconteurNode > & node,
boost::asio::io_context & io_context )
inline

Construct an IOContextThreadPool_AsyncResultAdapter.

Should be constructed on the stack

Parameters
nodeThe node that will use the adapter
io_contextThe single threaded IO Context

◆ IOContextThreadPool_AsyncResultAdapter() [2/2]

template<typename T>
RobotRaconteur::IOContextThreadPool_AsyncResultAdapter< T >::IOContextThreadPool_AsyncResultAdapter ( boost::asio::io_context & io_context)
inline

Construct an IOContextThreadPool_AsyncResultAdapter for the singleton RobotRaconteurNode.

Should be constructed on the stack

Parameters
io_contextThe single threaded IO Context

Member Function Documentation

◆ GetResult()

template<typename T>
result_type RobotRaconteur::IOContextThreadPool_AsyncResultAdapter< T >::GetResult ( )
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.

Returns
result_type The result of the operation

◆ PollResult()

template<typename T>
bool RobotRaconteur::IOContextThreadPool_AsyncResultAdapter< T >::PollResult ( result_type & ret,
boost::shared_ptr< RobotRaconteurException > & exp )
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.

Parameters
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
Returns
true The result is ready, ret and exp are valid
false The result is not ready, ret and exp are invalid

The documentation for this class was generated from the following file: