mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 01:06:44 +08:00
streamline error handling approaches
This commit is contained in:
parent
fb7074cc87
commit
f09fe50998
@ -30,23 +30,23 @@
|
|||||||
#ifndef CONTINUABLE_DETAIL_ASIO_HPP_INCLUDED
|
#ifndef CONTINUABLE_DETAIL_ASIO_HPP_INCLUDED
|
||||||
#define CONTINUABLE_DETAIL_ASIO_HPP_INCLUDED
|
#define CONTINUABLE_DETAIL_ASIO_HPP_INCLUDED
|
||||||
|
|
||||||
#include <continuable/detail/core/base.hpp>
|
#include <continuable/detail/features.hpp>
|
||||||
|
|
||||||
#if defined(ASIO_STANDALONE)
|
#if defined(ASIO_STANDALONE)
|
||||||
#include <asio/async_result.hpp>
|
#include <asio/async_result.hpp>
|
||||||
#include <asio/error_code.hpp>
|
#include <asio/error_code.hpp>
|
||||||
#include <asio/version.hpp>
|
#include <asio/version.hpp>
|
||||||
|
|
||||||
|
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
||||||
|
#include <asio/system_error.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if (ASIO_VERSION / 100 % 1000) <= 12
|
#if (ASIO_VERSION / 100 % 1000) <= 12
|
||||||
#define CTI_DETAIL_ASIO_HAS_NO_INTEGRATION
|
#define CTI_DETAIL_ASIO_HAS_NO_INTEGRATION
|
||||||
#elif (ASIO_VERSION / 100 % 1000) <= 14
|
#elif (ASIO_VERSION / 100 % 1000) <= 14
|
||||||
#define CTI_DETAIL_ASIO_HAS_EXPLICIT_RET_TYPE_INTEGRATION
|
#define CTI_DETAIL_ASIO_HAS_EXPLICIT_RET_TYPE_INTEGRATION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
|
||||||
#include <asio/system_error.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CTI_DETAIL_ASIO_NAMESPACE_BEGIN namespace asio {
|
#define CTI_DETAIL_ASIO_NAMESPACE_BEGIN namespace asio {
|
||||||
#define CTI_DETAIL_ASIO_NAMESPACE_END }
|
#define CTI_DETAIL_ASIO_NAMESPACE_END }
|
||||||
#else
|
#else
|
||||||
@ -54,16 +54,16 @@
|
|||||||
#include <boost/system/error_code.hpp>
|
#include <boost/system/error_code.hpp>
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
|
|
||||||
|
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
||||||
|
#include <boost/system/system_error.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if (BOOST_VERSION / 100 % 1000) <= 69
|
#if (BOOST_VERSION / 100 % 1000) <= 69
|
||||||
#define CTI_DETAIL_ASIO_HAS_NO_INTEGRATION
|
#define CTI_DETAIL_ASIO_HAS_NO_INTEGRATION
|
||||||
#elif (BOOST_VERSION / 100 % 1000) <= 71
|
#elif (BOOST_VERSION / 100 % 1000) <= 71
|
||||||
#define CTI_DETAIL_ASIO_HAS_EXPLICIT_RET_TYPE_INTEGRATION
|
#define CTI_DETAIL_ASIO_HAS_EXPLICIT_RET_TYPE_INTEGRATION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
|
||||||
#include <boost/system/system_error.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CTI_DETAIL_ASIO_NAMESPACE_BEGIN \
|
#define CTI_DETAIL_ASIO_NAMESPACE_BEGIN \
|
||||||
namespace boost { \
|
namespace boost { \
|
||||||
namespace asio {
|
namespace asio {
|
||||||
@ -79,48 +79,32 @@
|
|||||||
"integrated manually with `cti::promisify`."
|
"integrated manually with `cti::promisify`."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <continuable/detail/core/base.hpp>
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
||||||
|
#include <exception>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace cti {
|
namespace cti {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
namespace asio {
|
namespace asio {
|
||||||
|
|
||||||
#if defined(ASIO_STANDALONE)
|
#if defined(ASIO_STANDALONE)
|
||||||
using error_code_t = ::asio::error_code;
|
using error_code_t = ::asio::error_code;
|
||||||
using error_cond_t = std::error_condition;
|
|
||||||
|
|
||||||
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
||||||
using exception_t = ::asio::system_error;
|
using system_error_t = ::asio::system_error;
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
using error_code_t = ::boost::system::error_code;
|
using error_code_t = ::boost::system::error_code;
|
||||||
using error_cond_t = ::boost::system::error_condition;
|
|
||||||
|
|
||||||
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
||||||
using exception_t = ::boost::system::system_error;
|
using system_error_t = ::boost::system::system_error;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
|
||||||
template <typename Promise>
|
|
||||||
void promise_exception_helper(Promise& promise, error_code_t e) noexcept {
|
|
||||||
promise.set_exception(std::make_exception_ptr(exception_t(std::move(e))));
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
template <typename Promise>
|
|
||||||
void promise_exception_helper(Promise& promise, error_code_t e) noexcept
|
|
||||||
->decltype(promise.set_exception(std::move(e))) {
|
|
||||||
return promise.set_exception(std::move(e));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Promise>
|
|
||||||
void promise_exception_helper(Promise& promise, error_code_t e) noexcept
|
|
||||||
->decltype(promise.set_exception(error_cond_t(e.value(), e.category()))) {
|
|
||||||
promise.set_exception(error_cond_t(e.value(), e.category()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Binds `promise` to the first argument of a continuable resolver, giving it
|
// Binds `promise` to the first argument of a continuable resolver, giving it
|
||||||
// the signature of an ASIO handler.
|
// the signature of an ASIO handler.
|
||||||
template <typename Promise>
|
template <typename Promise>
|
||||||
@ -128,7 +112,12 @@ auto promise_resolver_handler(Promise&& promise) noexcept {
|
|||||||
return [promise = std::forward<Promise>(promise)](
|
return [promise = std::forward<Promise>(promise)](
|
||||||
error_code_t e, auto&&... args) mutable noexcept {
|
error_code_t e, auto&&... args) mutable noexcept {
|
||||||
if (e) {
|
if (e) {
|
||||||
promise_exception_helper(promise, std::move(e));
|
#if defined(CONTINUABLE_HAS_EXCEPTIONS)
|
||||||
|
promise.set_exception(
|
||||||
|
std::make_exception_ptr(system_error_t(std::move(e))));
|
||||||
|
#else
|
||||||
|
promise.set_exception(cti::exception_t(e.value(), e.category()));
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
promise.set_value(std::forward<decltype(args)>(args)...);
|
promise.set_value(std::forward<decltype(args)>(args)...);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user