mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 08:46:44 +08:00
Attempt to remove the plain handler
This commit is contained in:
parent
b77e926c41
commit
f1f9d61952
@ -316,14 +316,14 @@ public:
|
||||
/// \returns Returns a continuable_base with an asynchronous return type
|
||||
/// depending on the previous result type.
|
||||
///
|
||||
///
|
||||
/// \since 2.0.0
|
||||
template <typename T, typename E = detail::types::this_thread_executor_tag>
|
||||
auto fail(T&& callback,
|
||||
E&& executor = detail::types::this_thread_executor_tag{}) && {
|
||||
return detail::base::chain_continuation<detail::base::handle_results::no,
|
||||
detail::base::handle_errors::plain>(
|
||||
std::move(*this).finish(), std::forward<T>(callback),
|
||||
return detail::base::chain_continuation<
|
||||
detail::base::handle_results::no, detail::base::handle_errors::forward>(
|
||||
std::move(*this).finish(),
|
||||
detail::base::strip_exception_arg(std::forward<T>(callback)),
|
||||
std::forward<E>(executor));
|
||||
}
|
||||
|
||||
@ -345,9 +345,8 @@ public:
|
||||
/// \since 2.0.0
|
||||
template <typename OData, typename OAnnotation>
|
||||
auto fail(continuable_base<OData, OAnnotation>&& continuation) && {
|
||||
continuation.freeze();
|
||||
return std::move(*this).fail(
|
||||
[continuation = std::move(continuation)](exception_t) mutable {
|
||||
[continuation = std::move(continuation).freeze()](exception_t) mutable {
|
||||
std::move(continuation).done();
|
||||
});
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ namespace cti {
|
||||
/// for whether it resolves the callback instantly with its arguments
|
||||
/// without having side effects.
|
||||
///
|
||||
/// \since 3.1.0
|
||||
/// \since 4.0.0
|
||||
struct is_ready_arg_t {};
|
||||
|
||||
/// Represents the tag type that is used to query the continuation
|
||||
@ -81,7 +81,7 @@ struct is_ready_arg_t {};
|
||||
/// without having side effects.
|
||||
/// It's required that the query of is_ready_arg_t returns true.
|
||||
///
|
||||
/// \since 3.1.0
|
||||
/// \since 4.0.0
|
||||
struct get_arg_t {};
|
||||
|
||||
/// Represents the tag type that is used to disambiguate the
|
||||
@ -89,7 +89,7 @@ struct get_arg_t {};
|
||||
///
|
||||
/// \note see continuable::next for details.
|
||||
///
|
||||
/// \since 3.1.0
|
||||
/// \since 4.0.0
|
||||
struct exception_arg_t {};
|
||||
|
||||
/// \copydoc exception_arg_t
|
||||
@ -110,7 +110,7 @@ typedef exception_arg_t dispatch_error_tag;
|
||||
/// A custom error type may be set through
|
||||
/// defining `CONTINUABLE_WITH_CUSTOM_ERROR_TYPE`.
|
||||
///
|
||||
/// \since 3.1.0
|
||||
/// \since 4.0.0
|
||||
using exception_t = detail::types::exception_t;
|
||||
|
||||
/// \copydoc exception_t
|
||||
|
||||
@ -387,7 +387,6 @@ enum class handle_results {
|
||||
/// Tells whether we handle the error through the callback
|
||||
enum class handle_errors {
|
||||
no, //< The error is forwarded to the next callable
|
||||
plain, //< The error is the only argument accepted by the callable
|
||||
forward //< The error is forwarded to the callable while keeping its tag
|
||||
};
|
||||
/// \endcond
|
||||
@ -438,24 +437,6 @@ struct error_handler_base<handle_errors::no, Base> {
|
||||
}
|
||||
};
|
||||
template <typename Base>
|
||||
struct error_handler_base<handle_errors::plain, Base> {
|
||||
/// The operator which is called when an error occurred
|
||||
void operator()(exception_arg_t, exception_t exception) && {
|
||||
constexpr auto result = traits::identify<decltype(
|
||||
util::partial_invoke(std::move(static_cast<Base*>(this)->callback_),
|
||||
std::move(exception)))>{};
|
||||
|
||||
auto invoker = decoration::exception_invoker_of(result);
|
||||
|
||||
// Invoke the error handler
|
||||
on_executor(std::move(static_cast<Base*>(this)->executor_),
|
||||
std::move(invoker),
|
||||
std::move(static_cast<Base*>(this)->callback_),
|
||||
std::move(static_cast<Base*>(this)->next_callback_),
|
||||
std::move(exception));
|
||||
}
|
||||
};
|
||||
template <typename Base>
|
||||
struct error_handler_base<handle_errors::forward, Base> {
|
||||
/// The operator which is called when an error occurred
|
||||
void operator()(exception_arg_t, exception_t exception) && {
|
||||
@ -543,6 +524,7 @@ auto make_callback(Callback&& callback, Executor&& executor,
|
||||
std::forward<NextCallback>(next_callback)};
|
||||
}
|
||||
|
||||
// TODO fixate the args
|
||||
/// Once this was a workaround for GCC bug:
|
||||
/// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64095
|
||||
struct final_callback : util::non_copyable {
|
||||
@ -605,6 +587,18 @@ next_hint_of(std::integral_constant<handle_results, handle_results::no>,
|
||||
return current;
|
||||
}
|
||||
|
||||
/// Removes the exception_arg_t from the arguments passed to the given callable
|
||||
template <typename Callable>
|
||||
auto strip_exception_arg(Callable&& callable) {
|
||||
return [callable = std::forward<Callable>(callable)] //
|
||||
(exception_arg_t, auto&&... args) mutable
|
||||
-> decltype(util::invoke(std::declval<Callable>(), //
|
||||
std::declval<decltype(args)>()...)) {
|
||||
return util::invoke(std::move(callable), //
|
||||
std::forward<decltype(args)>(args)...);
|
||||
};
|
||||
}
|
||||
|
||||
/// Chains a callback together with a continuation and returns a continuation:
|
||||
///
|
||||
/// For example given:
|
||||
|
||||
@ -26,7 +26,4 @@ using namespace cti;
|
||||
|
||||
int main(int, char**) {
|
||||
// ...
|
||||
make_exceptional_continuable<int>(exception_t{}).fail([](exception_t) {
|
||||
// ...
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user