detail::solver< void, traits >

Module: Asynchronous Operations

A specialized template of the solver class which wraps void results. The solver class wraps a result that can be resolved in the future and stores the respective callbacks to be executed when the result is available or an error occurs. Usually, an asynchronous method creates a shared instance of this object and passes back its copy to the caller. The caller can then set callbacks on this solver. When the asynchronous operation completes or fails, the solver is resolved or failed and the callbacks which were set by the caller are invoked. If the solver is resolved/failed by the time the caller sets the callbacks, the callbacks are invoked immediately on the caller's thread. Otherwise, they are invoked when the solver is resolved/failed on the thread which resolved/failed the solver.

Template Parameters:

  • traits The traits of the solver that is thread-safe or non-thread-safe.

#include <async_result_detail.h>

Inherits from std::enable_shared_from_this< solver< void, traits > >

Public Functions

Name
~solver()
The destructor which ensures that the solver is reset before destruction.
solver() =default
The default constructor.
boolset_propagate_error_callback(err_cb_type && cb)
Sets the error function object callback on the solver. If the solver fails, the error callback is executed immediately. Otherwise, the callback is stored and will be executed later.
boolset_error_callback(err_cb_type && cb)
Sets the local error function object callback on the solver. If an error for this solver is available and the solver failed, the error callback is executed immediately. Otherwise, the callback is stored and will be executed later.
template <typename Z >
void
set_callbacks_from(solver_ptr< void, Z > other)
Sets respective callbacks for the current solver that resolves or fails the passed solver depending on whether the current solver is resolved or failed. If the current solver is resolved/failed, this method synchronously resolves/fails the passed solver. Otherwise, the method resolves/fails the passed solver when it resolves/fails. This allows the solver created and returned from the async_result::then call to have its callbacks invoked when the solver to which it is chained is resolved. It allows for chaining async_results together.
boolset_callback(result_cb_type && cb)
Sets a function object callback on the solver. If the solver is available resolves, the callback is executed immediately. Otherwise, the callback is stored.
voidresolve()
Resolves the solver, which means that the async operation for which this solver was created is completed. If there is a callback stored in the solver, the callback is executed immediately in this method. Otherwise, the result flag is set and the stored callback is invoked. The resolved solver indicates a successful asynchronous operation.
voidfail(std::exceptionptr && error)
Fails the solver in the case of an exception in the operation chain. If local_err_cb
is set for this solver, the cb is invoked with std::exceptionptr. If propagate_error_cb is set on the solver, the solver is invoked with std::exceptionptr. If there is no propagate_err_cb set on the solver, the exception pointer is stored in err_ member and is invoked when the respective callbacks are set.

Protected Functions

Name
voidreset()
voidpropagate_error(std::exception_ptr && error)
voidhandle_error_locally(std::exception_ptr && error)

Protected Attributes

Name
err_cb_typepropagateerr_cb
lock_typelock_
err_cb_typelocalerr_cb
boolhasresult
std::exception_ptrerr_
result_cb_typecb_
template <typename traits >
class dolbyio::comms::detail::solver< void, traits >;

Public Functions Documentation

function ~solver

inline ~solver()

The destructor which ensures that the solver is reset before destruction.

function solver

solver() =default

The default constructor.

function set_propagate_error_callback

inline bool set_propagate_error_callback(
    err_cb_type && cb
)

Sets the error function object callback on the solver. If the solver fails, the error callback is executed immediately. Otherwise, the callback is stored and will be executed later.

Parameters:

  • cb The function object to call in the case of an error to pass it to the exception pointer.

Return: A boolean indicating whether the function object is invoked.

function set_error_callback

inline bool set_error_callback(
    err_cb_type && cb
)

Sets the local error function object callback on the solver. If an error for this solver is available and the solver failed, the error callback is executed immediately. Otherwise, the callback is stored and will be executed later.

Parameters:

  • cb The function object to call in the case of an error.

Return: A boolean indicating whether the function object is invoked.

function set_callbacks_from

template <typename Z >
inline void set_callbacks_from(
    solver_ptr< void, Z > other
)

Sets respective callbacks for the current solver that resolves or fails the passed solver depending on whether the current solver is resolved or failed. If the current solver is resolved/failed, this method synchronously resolves/fails the passed solver. Otherwise, the method resolves/fails the passed solver when it resolves/fails. This allows the solver created and returned from the async_result::then call to have its callbacks invoked when the solver to which it is chained is resolved. It allows for chaining async_results together.

Parameters:

  • other The shared pointer to the previous solver.

Template Parameters:

  • Z Traits of the previous solver.

function set_callback

inline bool set_callback(
    result_cb_type && cb
)

Sets a function object callback on the solver. If the solver is available resolves, the callback is executed immediately. Otherwise, the callback is stored.

Parameters:

  • cb The function object to call in the case of success.

Return: A boolean indicating whether the function object is invoked.

function resolve

inline void resolve()

Resolves the solver, which means that the async operation for which this solver was created is completed. If there is a callback stored in the solver, the callback is executed immediately in this method. Otherwise, the result flag is set and the stored callback is invoked. The resolved solver indicates a successful asynchronous operation.

function fail

inline void fail(
    std::exception_ptr && error
)

Fails the solver in the case of an exception in the operation chain. If localerr_cb is set for this solver, the cb is invoked with std::exceptionptr. If propagate_error_cb is set on the solver, the solver is invoked with std::exceptionptr. If there is no propagate_err_cb set on the solver, the exception pointer is stored in err_ member and is invoked when the respective callbacks are set.

Parameters:

  • error The exception pointer containing the exception thrown during an asynchronous operation.

Protected Functions Documentation

function reset

inline void reset()

function propagate_error

inline void propagate_error(
    std::exception_ptr && error
)

function handle_error_locally

inline void handle_error_locally(
    std::exception_ptr && error
)

Protected Attributes Documentation

variable propagateerr_cb

err_cb_type propagate_err_cb_ {};

variable lock_

lock_type lock_;

variable localerr_cb

err_cb_type local_err_cb_ {};

variable hasresult

bool has_result_ = false;

variable err_

std::exception_ptr err_ {};

variable cb_

result_cb_type cb_ {};


Did this page help you?