mirror of
https://github.com/Naios/continuable.git
synced 2025-12-08 01:36:46 +08:00
Rename composition to connection
This commit is contained in:
parent
093ecae1c0
commit
9ab9b5e7fb
@ -37,14 +37,14 @@
|
||||
#include <utility>
|
||||
|
||||
#include <continuable/detail/base.hpp>
|
||||
#include <continuable/detail/composition-all.hpp>
|
||||
#include <continuable/detail/composition-any.hpp>
|
||||
#include <continuable/detail/composition-seq.hpp>
|
||||
#include <continuable/detail/composition.hpp>
|
||||
#include <continuable/detail/connection-all.hpp>
|
||||
#include <continuable/detail/connection-any.hpp>
|
||||
#include <continuable/detail/connection-seq.hpp>
|
||||
#include <continuable/detail/connection.hpp>
|
||||
#include <continuable/detail/features.hpp>
|
||||
#include <continuable/detail/traits.hpp>
|
||||
#include <continuable/detail/types.hpp>
|
||||
#include <continuable/detail/util.hpp>
|
||||
#include <continuable/detail/features.hpp>
|
||||
|
||||
#ifdef CONTINUABLE_HAS_EXPERIMENTAL_COROUTINE
|
||||
#include <continuable/detail/awaiting.hpp>
|
||||
@ -490,8 +490,8 @@ public:
|
||||
/// \since 1.0.0
|
||||
template <typename OData, typename OAnnotation>
|
||||
auto operator&&(continuable_base<OData, OAnnotation>&& right) && {
|
||||
return detail::composition::connect(
|
||||
detail::composition::composition_strategy_all_tag{}, std::move(*this),
|
||||
return detail::connection::connect(
|
||||
detail::connection::connection_strategy_all_tag{}, std::move(*this),
|
||||
std::move(right));
|
||||
}
|
||||
|
||||
@ -528,8 +528,8 @@ public:
|
||||
/// \since 1.0.0
|
||||
template <typename OData, typename OAnnotation>
|
||||
auto operator||(continuable_base<OData, OAnnotation>&& right) && {
|
||||
return detail::composition::connect(
|
||||
detail::composition::composition_strategy_any_tag{}, std::move(*this),
|
||||
return detail::connection::connect(
|
||||
detail::connection::connection_strategy_any_tag{}, std::move(*this),
|
||||
std::move(right));
|
||||
}
|
||||
|
||||
@ -557,8 +557,8 @@ public:
|
||||
/// \since 1.0.0
|
||||
template <typename OData, typename OAnnotation>
|
||||
auto operator>>(continuable_base<OData, OAnnotation>&& right) && {
|
||||
return detail::composition::seq::sequential_connect(std::move(*this),
|
||||
std::move(right));
|
||||
return detail::connection::seq::sequential_connect(std::move(*this),
|
||||
std::move(right));
|
||||
}
|
||||
|
||||
/// Invokes the continuation chain manually even before the
|
||||
@ -695,7 +695,7 @@ private:
|
||||
}
|
||||
|
||||
auto materialize() && {
|
||||
return detail::composition::materializer<continuable_base>::apply(
|
||||
return detail::connection::materializer<continuable_base>::apply(
|
||||
std::move(*this));
|
||||
}
|
||||
|
||||
|
||||
@ -36,10 +36,10 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <continuable/detail/composition-all.hpp>
|
||||
#include <continuable/detail/composition-any.hpp>
|
||||
#include <continuable/detail/composition-seq.hpp>
|
||||
#include <continuable/detail/composition.hpp>
|
||||
#include <continuable/detail/connection-all.hpp>
|
||||
#include <continuable/detail/connection-any.hpp>
|
||||
#include <continuable/detail/connection-seq.hpp>
|
||||
#include <continuable/detail/connection.hpp>
|
||||
#include <continuable/detail/range.hpp>
|
||||
|
||||
namespace cti {
|
||||
@ -77,8 +77,8 @@ namespace cti {
|
||||
/// \since 1.1.0
|
||||
template <typename... Args>
|
||||
auto when_all(Args&&... args) {
|
||||
return detail::composition::apply_composition(
|
||||
detail::composition::composition_strategy_all_tag{},
|
||||
return detail::connection::apply_connection(
|
||||
detail::connection::connection_strategy_all_tag{},
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@ -146,8 +146,8 @@ auto when_all(Iterator begin, Iterator end) {
|
||||
/// \since 1.1.0
|
||||
template <typename... Args>
|
||||
auto when_seq(Args&&... args) {
|
||||
return detail::composition::apply_composition(
|
||||
detail::composition::composition_strategy_seq_tag{},
|
||||
return detail::connection::apply_connection(
|
||||
detail::connection::connection_strategy_seq_tag{},
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@ -214,8 +214,8 @@ auto when_seq(Iterator begin, Iterator end) {
|
||||
/// \since 1.1.0
|
||||
template <typename... Args>
|
||||
auto when_any(Args&&... args) {
|
||||
return detail::composition::apply_composition(
|
||||
detail::composition::composition_strategy_any_tag{},
|
||||
return detail::connection::apply_connection(
|
||||
detail::connection::connection_strategy_any_tag{},
|
||||
std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
@ -43,14 +43,14 @@
|
||||
|
||||
namespace cti {
|
||||
namespace detail {
|
||||
namespace composition {
|
||||
namespace connection {
|
||||
/// This namespace provides utilities for performing compound
|
||||
/// connections between deeply nested continuables and values.
|
||||
///
|
||||
/// We create the result pack from the provides values and
|
||||
/// the async values if those are default constructible,
|
||||
/// otherwise use a lazy initialization wrapper and unwrap
|
||||
/// the whole pack when the composition is finished.
|
||||
/// the whole pack when the connection is finished.
|
||||
/// - value -> value
|
||||
/// - single async value -> single value
|
||||
/// - multiple async value -> tuple of async values.
|
||||
@ -68,7 +68,7 @@ decltype(auto) unpack_lazy(T&& value) {
|
||||
template <typename T>
|
||||
T&& unpack_lazy(container::flat_variant<T>&& value) {
|
||||
assert(value.template is<T>() &&
|
||||
"The composition was finalized before all values were present!");
|
||||
"The connection was finalized before all values were present!");
|
||||
|
||||
return std::move(value.template cast<T>());
|
||||
}
|
||||
@ -234,7 +234,7 @@ constexpr auto hint_of_data() {
|
||||
return decltype(finalize_data(detail::hint_mapper{}, std::declval<Data>())){};
|
||||
}
|
||||
} // namespace aggregated
|
||||
} // namespace composition
|
||||
} // namespace connection
|
||||
} // namespace detail
|
||||
} // namespace cti
|
||||
|
||||
|
||||
@ -39,15 +39,15 @@
|
||||
#include <utility>
|
||||
|
||||
#include <continuable/detail/base.hpp>
|
||||
#include <continuable/detail/composition-aggregated.hpp>
|
||||
#include <continuable/detail/composition.hpp>
|
||||
#include <continuable/detail/connection-aggregated.hpp>
|
||||
#include <continuable/detail/connection.hpp>
|
||||
#include <continuable/detail/hints.hpp>
|
||||
#include <continuable/detail/traits.hpp>
|
||||
#include <continuable/detail/types.hpp>
|
||||
|
||||
namespace cti {
|
||||
namespace detail {
|
||||
namespace composition {
|
||||
namespace connection {
|
||||
namespace all {
|
||||
/// Caches the partial results and invokes the callback when all results
|
||||
/// are arrived. This class is thread safe.
|
||||
@ -100,7 +100,7 @@ class result_submitter
|
||||
|
||||
template <typename... PartialArgs>
|
||||
void operator()(types::dispatch_error_tag tag, types::error_type error) && {
|
||||
// We never complete the composition, but we forward the first error
|
||||
// We never complete the connection, but we forward the first error
|
||||
// which was raised.
|
||||
std::call_once(me->flag_, std::move(me->callback_), tag,
|
||||
std::move(error));
|
||||
@ -121,7 +121,7 @@ public:
|
||||
}
|
||||
|
||||
/// Initially the counter is created with an initial count of 1 in order
|
||||
/// to prevent that the composition is finished before all callbacks
|
||||
/// to prevent that the connection is finished before all callbacks
|
||||
/// were registered.
|
||||
void accept() {
|
||||
complete_one();
|
||||
@ -145,20 +145,20 @@ struct continuable_dispatcher {
|
||||
};
|
||||
} // namespace all
|
||||
|
||||
struct composition_strategy_all_tag {};
|
||||
struct connection_strategy_all_tag {};
|
||||
template <>
|
||||
struct is_composition_strategy<composition_strategy_all_tag> // ...
|
||||
struct is_connection_strategy<connection_strategy_all_tag> // ...
|
||||
: std::true_type {};
|
||||
|
||||
/// Finalizes the all logic of a given composition
|
||||
/// Finalizes the all logic of a given connection
|
||||
template <>
|
||||
struct composition_finalizer<composition_strategy_all_tag> {
|
||||
/// Finalizes the all logic of a given composition
|
||||
template <typename Composition>
|
||||
static auto finalize(Composition&& composition, util::ownership ownership) {
|
||||
// Create the target result from the composition
|
||||
struct connection_finalizer<connection_strategy_all_tag> {
|
||||
/// Finalizes the all logic of a given connection
|
||||
template <typename Connection>
|
||||
static auto finalize(Connection&& connection, util::ownership ownership) {
|
||||
// Create the target result from the connection
|
||||
auto result =
|
||||
aggregated::box_continuables(std::forward<Composition>(composition));
|
||||
aggregated::box_continuables(std::forward<Connection>(connection));
|
||||
|
||||
auto signature = aggregated::hint_of_data<decltype(result)>();
|
||||
|
||||
@ -179,13 +179,13 @@ struct composition_finalizer<composition_strategy_all_tag> {
|
||||
traverse_pack(all::continuable_dispatcher<submitter_t>{state},
|
||||
state->head());
|
||||
|
||||
// Finalize the composition if all results arrived in-place
|
||||
// Finalize the connection if all results arrived in-place
|
||||
state->accept();
|
||||
},
|
||||
signature, std::move(ownership));
|
||||
}
|
||||
};
|
||||
} // namespace composition
|
||||
} // namespace connection
|
||||
} // namespace detail
|
||||
} // namespace cti
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
|
||||
namespace cti {
|
||||
namespace detail {
|
||||
namespace composition {
|
||||
namespace connection {
|
||||
namespace any {
|
||||
/// Invokes the callback with the first arriving result
|
||||
template <typename T>
|
||||
@ -160,23 +160,23 @@ struct continuable_dispatcher {
|
||||
};
|
||||
} // namespace any
|
||||
|
||||
struct composition_strategy_any_tag {};
|
||||
struct connection_strategy_any_tag {};
|
||||
template <>
|
||||
struct is_composition_strategy<composition_strategy_any_tag> // ...
|
||||
struct is_connection_strategy<connection_strategy_any_tag> // ...
|
||||
: std::true_type {};
|
||||
|
||||
/// Finalizes the any logic of a given composition
|
||||
/// Finalizes the any logic of a given connection
|
||||
template <>
|
||||
struct composition_finalizer<composition_strategy_any_tag> {
|
||||
template <typename Composition>
|
||||
static auto finalize(Composition&& composition, util::ownership ownership) {
|
||||
struct connection_finalizer<connection_strategy_any_tag> {
|
||||
template <typename Connection>
|
||||
static auto finalize(Connection&& connection, util::ownership ownership) {
|
||||
auto signature = decltype(any::result_deducer::deduce(
|
||||
traversal::container_category_of_t<std::decay_t<Composition>>{},
|
||||
traits::identity<std::decay_t<Composition>>{})){};
|
||||
traversal::container_category_of_t<std::decay_t<Connection>>{},
|
||||
traits::identity<std::decay_t<Connection>>{})){};
|
||||
|
||||
return base::attorney::create(
|
||||
[composition =
|
||||
std::forward<Composition>(composition)](auto&& callback) mutable {
|
||||
[connection =
|
||||
std::forward<Connection>(connection)](auto&& callback) mutable {
|
||||
|
||||
using submitter_t =
|
||||
any::any_result_submitter<std::decay_t<decltype(callback)>>;
|
||||
@ -187,12 +187,12 @@ struct composition_finalizer<composition_strategy_any_tag> {
|
||||
std::forward<decltype(callback)>(callback));
|
||||
|
||||
traverse_pack(any::continuable_dispatcher<submitter_t>{submitter},
|
||||
std::move(composition));
|
||||
std::move(connection));
|
||||
},
|
||||
signature, std::move(ownership));
|
||||
}
|
||||
};
|
||||
} // namespace composition
|
||||
} // namespace connection
|
||||
} // namespace detail
|
||||
} // namespace cti
|
||||
|
||||
|
||||
@ -39,13 +39,13 @@
|
||||
|
||||
#include <continuable/continuable-traverse-async.hpp>
|
||||
#include <continuable/detail/base.hpp>
|
||||
#include <continuable/detail/composition-aggregated.hpp>
|
||||
#include <continuable/detail/connection-aggregated.hpp>
|
||||
#include <continuable/detail/traits.hpp>
|
||||
#include <continuable/detail/util.hpp>
|
||||
|
||||
namespace cti {
|
||||
namespace detail {
|
||||
namespace composition {
|
||||
namespace connection {
|
||||
namespace seq {
|
||||
/// Connects the left and the right continuable to a sequence
|
||||
///
|
||||
@ -126,20 +126,20 @@ public:
|
||||
};
|
||||
} // namespace seq
|
||||
|
||||
struct composition_strategy_seq_tag {};
|
||||
struct connection_strategy_seq_tag {};
|
||||
template <>
|
||||
struct is_composition_strategy<composition_strategy_seq_tag> // ...
|
||||
struct is_connection_strategy<connection_strategy_seq_tag> // ...
|
||||
: std::true_type {};
|
||||
|
||||
/// Finalizes the seq logic of a given composition
|
||||
/// Finalizes the seq logic of a given connection
|
||||
template <>
|
||||
struct composition_finalizer<composition_strategy_seq_tag> {
|
||||
/// Finalizes the all logic of a given composition
|
||||
template <typename Composition>
|
||||
static auto finalize(Composition&& composition, util::ownership ownership) {
|
||||
struct connection_finalizer<connection_strategy_seq_tag> {
|
||||
/// Finalizes the all logic of a given connection
|
||||
template <typename Connection>
|
||||
static auto finalize(Connection&& connection, util::ownership ownership) {
|
||||
|
||||
auto result =
|
||||
aggregated::box_continuables(std::forward<Composition>(composition));
|
||||
aggregated::box_continuables(std::forward<Connection>(connection));
|
||||
|
||||
auto signature = aggregated::hint_of_data<decltype(result)>();
|
||||
|
||||
@ -161,7 +161,7 @@ struct composition_finalizer<composition_strategy_seq_tag> {
|
||||
signature, std::move(ownership));
|
||||
}
|
||||
};
|
||||
} // namespace composition
|
||||
} // namespace connection
|
||||
} // namespace detail
|
||||
} // namespace cti
|
||||
|
||||
|
||||
@ -44,17 +44,17 @@
|
||||
|
||||
namespace cti {
|
||||
namespace detail {
|
||||
/// The namespace `composition` offers methods to chain continuations together
|
||||
/// The namespace `connection` offers methods to chain continuations together
|
||||
/// with `all`, `any` or `seq` logic.
|
||||
namespace composition {
|
||||
namespace connection {
|
||||
template <typename T>
|
||||
struct is_composition_strategy // ...
|
||||
struct is_connection_strategy // ...
|
||||
: std::false_type {};
|
||||
|
||||
/// Adds the given continuation tuple to the left composition
|
||||
/// Adds the given continuation tuple to the left connection
|
||||
template <typename... LeftArgs, typename... RightArgs>
|
||||
auto chain_composition(std::tuple<LeftArgs...> leftPack,
|
||||
std::tuple<RightArgs...> rightPack) {
|
||||
auto chain_connection(std::tuple<LeftArgs...> leftPack,
|
||||
std::tuple<RightArgs...> rightPack) {
|
||||
|
||||
return traits::merge(std::move(leftPack), std::move(rightPack));
|
||||
}
|
||||
@ -67,7 +67,7 @@ auto chain_composition(std::tuple<LeftArgs...> leftPack,
|
||||
/// -> make a tuple containing the continuable as only element
|
||||
template <
|
||||
typename Strategy, typename Data, typename Annotation,
|
||||
std::enable_if_t<!is_composition_strategy<Annotation>::value>* = nullptr>
|
||||
std::enable_if_t<!is_connection_strategy<Annotation>::value>* = nullptr>
|
||||
auto normalize(Strategy /*strategy*/,
|
||||
continuable_base<Data, Annotation>&& continuation) {
|
||||
|
||||
@ -78,7 +78,7 @@ auto normalize(Strategy /*strategy*/,
|
||||
/// -> materialize it
|
||||
template <
|
||||
typename Strategy, typename Data, typename Annotation,
|
||||
std::enable_if_t<is_composition_strategy<Annotation>::value>* = nullptr>
|
||||
std::enable_if_t<is_connection_strategy<Annotation>::value>* = nullptr>
|
||||
auto normalize(Strategy /*strategy*/,
|
||||
continuable_base<Data, Annotation>&& continuation) {
|
||||
|
||||
@ -110,8 +110,8 @@ auto connect(Strategy strategy, continuable_base<LData, LAnnotation>&& left,
|
||||
|
||||
// Make the new data which consists of a tuple containing
|
||||
// all connected continuables.
|
||||
auto data = chain_composition(normalize(strategy, std::move(left)),
|
||||
normalize(strategy, std::move(right)));
|
||||
auto data = chain_connection(normalize(strategy, std::move(left)),
|
||||
normalize(strategy, std::move(right)));
|
||||
|
||||
// Return a new continuable containing the tuple and holding
|
||||
// the current strategy as annotation.
|
||||
@ -120,21 +120,21 @@ auto connect(Strategy strategy, continuable_base<LData, LAnnotation>&& left,
|
||||
|
||||
/// All strategies should specialize this class in order to provide:
|
||||
/// - A finalize static method that creates the callable object which
|
||||
/// is invoked with the callback to call when the composition is finished.
|
||||
/// is invoked with the callback to call when the connection is finished.
|
||||
/// - A static method hint that returns the new signature hint.
|
||||
template <typename Strategy>
|
||||
struct composition_finalizer;
|
||||
struct connection_finalizer;
|
||||
|
||||
/// Finalizes the connection logic of a given composition
|
||||
/// Finalizes the connection logic of a given connection
|
||||
template <typename Data, typename Strategy>
|
||||
auto finalize_composition(continuable_base<Data, Strategy>&& continuation) {
|
||||
using finalizer = composition_finalizer<Strategy>;
|
||||
auto finalize_connection(continuable_base<Data, Strategy>&& continuation) {
|
||||
using finalizer = connection_finalizer<Strategy>;
|
||||
|
||||
util::ownership ownership = base::attorney::ownership_of(continuation);
|
||||
auto composition = base::attorney::consume_data(std::move(continuation));
|
||||
auto connection = base::attorney::consume_data(std::move(continuation));
|
||||
|
||||
// Return a new continuable which
|
||||
return finalizer::finalize(std::move(composition), std::move(ownership));
|
||||
return finalizer::finalize(std::move(connection), std::move(ownership));
|
||||
}
|
||||
|
||||
/// A base class from which the continuable may inherit in order to
|
||||
@ -146,12 +146,11 @@ struct materializer {
|
||||
}
|
||||
};
|
||||
template <typename Data, typename Strategy>
|
||||
struct materializer<
|
||||
continuable_base<Data, Strategy>,
|
||||
std::enable_if_t<is_composition_strategy<Strategy>::value>> {
|
||||
struct materializer<continuable_base<Data, Strategy>,
|
||||
std::enable_if_t<is_connection_strategy<Strategy>::value>> {
|
||||
|
||||
static constexpr auto apply(continuable_base<Data, Strategy>&& continuable) {
|
||||
return finalize_composition(std::move(continuable));
|
||||
return finalize_connection(std::move(continuable));
|
||||
}
|
||||
};
|
||||
|
||||
@ -186,8 +185,8 @@ public:
|
||||
};
|
||||
|
||||
template <typename Strategy, typename... Args>
|
||||
auto apply_composition(Strategy, Args&&... args) {
|
||||
using finalizer = composition_finalizer<Strategy>;
|
||||
auto apply_connection(Strategy, Args&&... args) {
|
||||
using finalizer = connection_finalizer<Strategy>;
|
||||
|
||||
// Freeze every continuable inside the given arguments,
|
||||
// and freeze the ownership if one of the continuables
|
||||
@ -195,12 +194,12 @@ auto apply_composition(Strategy, Args&&... args) {
|
||||
// Additionally test whether every continuable is acquired.
|
||||
// Also materialize every continuable.
|
||||
util::ownership ownership;
|
||||
auto composition = map_pack(prepare_continuables{ownership},
|
||||
std::make_tuple(std::forward<Args>(args)...));
|
||||
auto connection = map_pack(prepare_continuables{ownership},
|
||||
std::make_tuple(std::forward<Args>(args)...));
|
||||
|
||||
return finalizer::finalize(std::move(composition), std::move(ownership));
|
||||
return finalizer::finalize(std::move(connection), std::move(ownership));
|
||||
}
|
||||
} // namespace composition
|
||||
} // namespace connection
|
||||
} // namespace detail
|
||||
} // namespace cti
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user