mirror of
https://github.com/Naios/continuable.git
synced 2026-02-16 23:29:48 +08:00
Make the ready query stuff part of the private API
This commit is contained in:
parent
b5f353222c
commit
d416698758
@ -564,7 +564,8 @@ public:
|
|||||||
|
|
||||||
#ifdef CONTINUABLE_HAS_DOXYGEN
|
#ifdef CONTINUABLE_HAS_DOXYGEN
|
||||||
/// Materializes the continuation expression template and finishes
|
/// Materializes the continuation expression template and finishes
|
||||||
/// the current applied strategy.
|
/// the current applied strategy such that the resulting continuable
|
||||||
|
/// will always be a concrete type and Continuable::is_concrete holds.
|
||||||
///
|
///
|
||||||
/// This can be used in the case where we are chaining continuations lazily
|
/// This can be used in the case where we are chaining continuations lazily
|
||||||
/// through a strategy, for instance when applying operators for
|
/// through a strategy, for instance when applying operators for
|
||||||
@ -589,24 +590,6 @@ public:
|
|||||||
unspecified finish() &&;
|
unspecified finish() &&;
|
||||||
#endif // CONTINUABLE_HAS_DOXYGEN
|
#endif // CONTINUABLE_HAS_DOXYGEN
|
||||||
|
|
||||||
#ifdef CONTINUABLE_HAS_DOXYGEN
|
|
||||||
/// Returns true if the continuable_base will resolve its promise
|
|
||||||
/// immediately on request.
|
|
||||||
///
|
|
||||||
/// \since 4.0.0
|
|
||||||
bool is_ready() const noexcept;
|
|
||||||
#endif // CONTINUABLE_HAS_DOXYGEN
|
|
||||||
|
|
||||||
#ifdef CONTINUABLE_HAS_DOXYGEN
|
|
||||||
/// Returns the result of this continuable immediatly.
|
|
||||||
///
|
|
||||||
/// \attention requires that this continuable resolves immediatly on
|
|
||||||
/// request which means that is_ready() holds.
|
|
||||||
///
|
|
||||||
/// \since 4.0.0
|
|
||||||
unspecified request() &&;
|
|
||||||
#endif // CONTINUABLE_HAS_DOXYGEN
|
|
||||||
|
|
||||||
/// Predicate to check whether the cti::continuable_base is frozen or not.
|
/// Predicate to check whether the cti::continuable_base is frozen or not.
|
||||||
///
|
///
|
||||||
/// \returns Returns true when the continuable_base is frozen.
|
/// \returns Returns true when the continuable_base is frozen.
|
||||||
@ -840,6 +823,7 @@ constexpr auto make_continuable(Continuation&& continuation) {
|
|||||||
"use make_continuable<void>(...). Continuables with an exact "
|
"use make_continuable<void>(...). Continuables with an exact "
|
||||||
"signature may be created through make_continuable<Args...>.");
|
"signature may be created through make_continuable<Args...>.");
|
||||||
|
|
||||||
|
// TODO
|
||||||
return detail::base::attorney::create_from(
|
return detail::base::attorney::create_from(
|
||||||
std::forward<Continuation>(continuation),
|
std::forward<Continuation>(continuation),
|
||||||
detail::hints::from_explicit(detail::traits::identity<Args...>{}),
|
detail::hints::from_explicit(detail::traits::identity<Args...>{}),
|
||||||
@ -857,7 +841,7 @@ constexpr auto make_continuable(Continuation&& continuation) {
|
|||||||
///
|
///
|
||||||
/// \since 3.0.0
|
/// \since 3.0.0
|
||||||
inline auto make_ready_continuable() {
|
inline auto make_ready_continuable() {
|
||||||
return make_continuable<void>(detail::base::ready_continuable<>());
|
return make_continuable<void>(detail::base::ready_continuation<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a continuable_base with one result value which instantly resolves
|
/// Returns a continuable_base with one result value which instantly resolves
|
||||||
@ -867,7 +851,7 @@ inline auto make_ready_continuable() {
|
|||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
auto make_ready_continuable(Args&&... args) {
|
auto make_ready_continuable(Args&&... args) {
|
||||||
return make_continuable<std::decay_t<Args>...>(
|
return make_continuable<std::decay_t<Args>...>(
|
||||||
detail::base::ready_continuable<std::decay_t<Args>...>(
|
detail::base::ready_continuation<std::decay_t<Args>...>(
|
||||||
std::forward<Args>(args)...));
|
std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -69,7 +69,7 @@ public:
|
|||||||
|
|
||||||
/// The continuable type for the given parameters.
|
/// The continuable type for the given parameters.
|
||||||
using continuable = continuable_base<
|
using continuable = continuable_base<
|
||||||
ContinuationWrapper<sizeof(detail::base::ready_continuable<Args...>),
|
ContinuationWrapper<sizeof(detail::base::ready_continuation<Args...>),
|
||||||
void(promise)>,
|
void(promise)>,
|
||||||
detail::traits::identity<Args...>>;
|
detail::traits::identity<Args...>>;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -143,8 +143,6 @@ struct connection_annotation_trait {
|
|||||||
return finalizer::finalize(std::move(connection), std::move(ownership));
|
return finalizer::finalize(std::move(connection), std::move(ownership));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using is_concrete = std::false_type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class prepare_continuables {
|
class prepare_continuables {
|
||||||
|
|||||||
@ -48,11 +48,7 @@ struct annotation_trait<traits::identity<Args...>> {
|
|||||||
Continuable&& finish() {
|
Continuable&& finish() {
|
||||||
return std::move(*static_cast<Continuable*>(this));
|
return std::move(*static_cast<Continuable*>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr bool is_concrete = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using is_concrete = std::true_type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace hints {
|
namespace hints {
|
||||||
|
|||||||
@ -70,15 +70,17 @@ template <typename Data, typename Annotation>
|
|||||||
struct is_continuable<continuable_base<Data, Annotation>> : std::true_type {};
|
struct is_continuable<continuable_base<Data, Annotation>> : std::true_type {};
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
struct ready_continuable {
|
struct ready_continuation {
|
||||||
std::tuple<Args...> values_;
|
std::tuple<Args...> values_;
|
||||||
|
|
||||||
ready_continuable(ready_continuable&&) = default;
|
ready_continuation() = delete;
|
||||||
ready_continuable(ready_continuable const&) = default;
|
~ready_continuation() = default;
|
||||||
ready_continuable& operator=(ready_continuable&&) = default;
|
ready_continuation(ready_continuation&&) = default;
|
||||||
ready_continuable& operator=(ready_continuable const&) = default;
|
ready_continuation(ready_continuation const&) = delete;
|
||||||
|
ready_continuation& operator=(ready_continuation&&) = default;
|
||||||
|
ready_continuation& operator=(ready_continuation const&) = delete;
|
||||||
|
|
||||||
explicit ready_continuable(Args... values) : values_(std::move(values)...) {
|
explicit ready_continuation(Args... values) : values_(std::move(values)...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
@ -86,43 +88,36 @@ struct ready_continuable {
|
|||||||
traits::unpack(std::forward<Callback>(callback), std::move(values_));
|
traits::unpack(std::forward<Callback>(callback), std::move(values_));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*bool operator()(is_ready_arg_t) const noexcept {
|
bool operator()(is_ready_arg_t) const noexcept {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<Args...> operator()(get_arg_t) && {
|
std::tuple<Args...> operator()(get_arg_t) && {
|
||||||
return std::move(values_);
|
return std::move(values_);
|
||||||
}*/
|
}
|
||||||
};
|
};
|
||||||
template <>
|
template <>
|
||||||
struct ready_continuable<> {
|
struct ready_continuation<> {
|
||||||
|
ready_continuation() = default;
|
||||||
|
~ready_continuation() = default;
|
||||||
|
ready_continuation(ready_continuation&&) = default;
|
||||||
|
ready_continuation(ready_continuation const&) = delete;
|
||||||
|
ready_continuation& operator=(ready_continuation&&) = default;
|
||||||
|
ready_continuation& operator=(ready_continuation const&) = delete;
|
||||||
|
|
||||||
template <typename Callback>
|
template <typename Callback>
|
||||||
void operator()(Callback&& callback) {
|
void operator()(Callback&& callback) {
|
||||||
util::invoke(std::forward<Callback>(callback));
|
util::invoke(std::forward<Callback>(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*bool operator()(is_ready_arg_t) const noexcept {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()(get_arg_t) && {
|
|
||||||
}*/
|
|
||||||
};
|
|
||||||
|
|
||||||
/*template <typename Continuation, typename Args>
|
|
||||||
struct proxy_continuable : Continuation {
|
|
||||||
using Continuation::Continuation;
|
|
||||||
|
|
||||||
using Continuation::operator();
|
|
||||||
|
|
||||||
bool operator()(is_ready_arg_t) const noexcept {
|
bool operator()(is_ready_arg_t) const noexcept {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<T...> operator()(get_arg_t) && {
|
std::tuple<> operator()(get_arg_t) && {
|
||||||
util::unreachable();
|
return std::make_tuple();
|
||||||
}
|
}
|
||||||
};*/
|
};
|
||||||
|
|
||||||
struct attorney {
|
struct attorney {
|
||||||
/// Creates a continuable_base from the given continuation, annotation
|
/// Creates a continuable_base from the given continuation, annotation
|
||||||
@ -681,13 +676,71 @@ auto strip_exception_arg(Callable&& callable) {
|
|||||||
return proxy{std::forward<Callable>(callable)};
|
return proxy{std::forward<Callable>(callable)};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Chains a callback together with a continuation and returns a continuation:
|
template <typename Hint, handle_results HandleResults,
|
||||||
|
handle_errors HandleErrors, typename Continuation, typename Callback,
|
||||||
|
typename Executor>
|
||||||
|
struct chained_continuation;
|
||||||
|
template <typename... Args, handle_results HandleResults,
|
||||||
|
handle_errors HandleErrors, typename Continuation, typename Callback,
|
||||||
|
typename Executor>
|
||||||
|
struct chained_continuation<traits::identity<Args...>, HandleResults,
|
||||||
|
HandleErrors, Continuation, Callback, Executor> {
|
||||||
|
Continuation continuation_;
|
||||||
|
Callback callback_;
|
||||||
|
Executor executor_;
|
||||||
|
|
||||||
|
explicit chained_continuation(Continuation continuation, Callback callback,
|
||||||
|
Executor executor)
|
||||||
|
: continuation_(std::move(continuation)), callback_(std::move(callback)),
|
||||||
|
executor_(std::move(executor)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
chained_continuation() = delete;
|
||||||
|
~chained_continuation() = default;
|
||||||
|
chained_continuation(chained_continuation const&) = delete;
|
||||||
|
chained_continuation(chained_continuation&&) = default;
|
||||||
|
chained_continuation& operator=(chained_continuation const&) = delete;
|
||||||
|
chained_continuation& operator=(chained_continuation&&) = default;
|
||||||
|
|
||||||
|
template <typename NextCallback>
|
||||||
|
void operator()(NextCallback&& next_callback) {
|
||||||
|
// Invokes a continuation with a given callback.
|
||||||
|
// Passes the next callback to the resulting continuable or
|
||||||
|
// invokes the next callback directly if possible.
|
||||||
|
//
|
||||||
|
// For example given:
|
||||||
|
// - Continuation: continuation<[](auto&& callback) { callback("hi"); }>
|
||||||
|
// - Callback: [](std::string) { }
|
||||||
|
// - NextCallback: []() { }
|
||||||
|
auto proxy = callbacks::make_callback<traits::identity<Args...>,
|
||||||
|
HandleResults, HandleErrors>(
|
||||||
|
std::move(callback_), std::move(executor_),
|
||||||
|
std::forward<decltype(next_callback)>(next_callback));
|
||||||
|
|
||||||
|
// Invoke the continuation with a proxy callback.
|
||||||
|
// The proxy callback is responsible for passing
|
||||||
|
// the result to the callback as well as decorating it.
|
||||||
|
invoke_continuation(std::move(continuation_), std::move(proxy));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator()(is_ready_arg_t) const noexcept {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::tuple<Args...> operator()(get_arg_t) && {
|
||||||
|
util::unreachable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Chains a callback together with a continuation and returns a
|
||||||
|
/// continuation:
|
||||||
///
|
///
|
||||||
/// For example given:
|
/// For example given:
|
||||||
/// - Continuation: continuation<[](auto&& callback) { callback("hi"); }>
|
/// - Continuation: continuation<[](auto&& callback) { callback("hi"); }>
|
||||||
/// - Callback: [](std::string) { }
|
/// - Callback: [](std::string) { }
|
||||||
///
|
///
|
||||||
/// This function returns a function accepting the next callback in the chain:
|
/// This function returns a function accepting the next callback in the
|
||||||
|
/// chain:
|
||||||
/// - Result: continuation<[](auto&& callback) { /*...*/ }>
|
/// - Result: continuation<[](auto&& callback) { /*...*/ }>
|
||||||
///
|
///
|
||||||
template <handle_results HandleResults, handle_errors HandleErrors,
|
template <handle_results HandleResults, handle_errors HandleErrors,
|
||||||
@ -706,29 +759,14 @@ auto chain_continuation(Continuation&& continuation, Callback&& callback,
|
|||||||
auto ownership_ = attorney::ownership_of(continuation);
|
auto ownership_ = attorney::ownership_of(continuation);
|
||||||
continuation.freeze();
|
continuation.freeze();
|
||||||
|
|
||||||
return attorney::create_from(
|
using continuation_t = chained_continuation<
|
||||||
[continuation = std::forward<Continuation>(continuation),
|
Hint, HandleResults, HandleErrors, traits::unrefcv_t<Continuation>,
|
||||||
callback = std::forward<Callback>(callback),
|
traits::unrefcv_t<Callback>, traits::unrefcv_t<Executor>>;
|
||||||
executor = std::forward<Executor>(executor)] //
|
|
||||||
(auto&& next_callback) mutable {
|
|
||||||
// Invokes a continuation with a given callback.
|
|
||||||
// Passes the next callback to the resulting continuable or
|
|
||||||
// invokes the next callback directly if possible.
|
|
||||||
//
|
|
||||||
// For example given:
|
|
||||||
// - Continuation: continuation<[](auto&& callback) { callback("hi"); }>
|
|
||||||
// - Callback: [](std::string) { }
|
|
||||||
// - NextCallback: []() { }
|
|
||||||
auto proxy =
|
|
||||||
callbacks::make_callback<Hint, HandleResults, HandleErrors>(
|
|
||||||
std::move(callback), std::move(executor),
|
|
||||||
std::forward<decltype(next_callback)>(next_callback));
|
|
||||||
|
|
||||||
// Invoke the continuation with a proxy callback.
|
return attorney::create_from(
|
||||||
// The proxy callback is responsible for passing
|
continuation_t(std::forward<Continuation>(continuation),
|
||||||
// the result to the callback as well as decorating it.
|
std::forward<Callback>(callback),
|
||||||
invoke_continuation(std::move(continuation), std::move(proxy));
|
std::forward<Executor>(executor)),
|
||||||
},
|
|
||||||
next_hint, ownership_);
|
next_hint, ownership_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user