OZO 「お象」
Boost.Asio and libpq based asynchronous PostgreSQL unofficial header-only C++17 client library.
ozo::failover::basic_try< Options, Context > Class Template Reference

#include <ozo/failover/retry.h>

Description

template<typename Options, typename Context>
class ozo::failover::basic_try< Options, Context >

Operation try representation.

Controls current try state incluiding number of tries remain, context of operation call for current try.

Template Parameters
Options— map of ozo::options.
Context— operation call context, literally operation arguments except CompletionToken.

Public Member Functions

constexpr basic_try (Options options, Context ctx)
 Construct a new basic try object. More...
 
auto get_context () const
 Get the operation context. More...
 
template<typename Connection >
std::optional< basic_tryget_next_try (ozo::error_code ec, Connection &&conn)
 Get the next try. More...
 
constexpr int tries_remain () const
 Number of tries remains. More...
 
constexpr decltype(auto) get_conditions () const
 Retry conditions for the try. More...
 

Constructors

◆ basic_try()

template<typename Options , typename Context >
constexpr ozo::failover::basic_try< Options, Context >::basic_try ( Options  options,
Context  ctx 
)
constexpr

Construct a new basic try object.

Parameters
options— map of ozo::failover::retry_options.
ctx— operation context, compartible with ozo::failover::basic_context

Member Function Documentation

◆ get_conditions()

template<typename Options , typename Context >
constexpr decltype(auto) ozo::failover::basic_try< Options, Context >::get_conditions ( ) const
constexpr

Retry conditions for the try.

Returns
auto — boost::hana::tuple of error conditions which have a good chance to be solved by a retry.

References ozo::failover::retry_options::conditions, and ozo::get_option().

◆ get_context()

template<typename Options , typename Context >
auto ozo::failover::basic_try< Options, Context >::get_context ( ) const

Get the operation context.

Returns
boost::hana::tuple — operation initiation context for the try with modified time constraint; see ozo::retry_strategy::tries() for details about calculations.

References ozo::unwrap().

◆ get_next_try()

template<typename Options , typename Context >
template<typename Connection >
std::optional<basic_try> ozo::failover::basic_try< Options, Context >::get_next_try ( ozo::error_code  ec,
Connection &&  conn 
)

Get the next try.

Return next try object for retry operation if it possible. See ozo::fallback::get_next_try() for details.

Parameters
ec— error code which should be examined for retry ability.
connConnection object which should be closed in any case.
Returns
std::optional<basic_try> — initialized with basic_try object if retry is possible.
std::nullopt — retry is not possible due to ec value or tries remain count.

References ozo::failover::retry_options::close_connection, ozo::defer_close_connection(), ozo::get_option(), and ozo::failover::retry_options::on_retry.

◆ tries_remain()

template<typename Options , typename Context >
constexpr int ozo::failover::basic_try< Options, Context >::tries_remain ( ) const
constexpr

Number of tries remains.

Returns
int — number of tries remains to execute an operation, not less than 0.

References ozo::get_option(), and ozo::failover::retry_options::tries.