|
| 1 | +// include/beman/execution26/detail/on.hpp -*-C++-*- |
| 2 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | + |
| 4 | +#ifndef INCLUDED_INCLUDE_BEMAN_EXECUTION26_DETAIL_ON |
| 5 | +#define INCLUDED_INCLUDE_BEMAN_EXECUTION26_DETAIL_ON |
| 6 | + |
| 7 | +#include <beman/execution26/detail/scheduler.hpp> |
| 8 | +#include <beman/execution26/detail/sender.hpp> |
| 9 | +#include <beman/execution26/detail/sender_adaptor_closure.hpp> |
| 10 | +#include <beman/execution26/detail/transform_sender.hpp> |
| 11 | +#include <beman/execution26/detail/query_with_default.hpp> |
| 12 | +#include <beman/execution26/detail/get_domain.hpp> |
| 13 | +#include <beman/execution26/detail/get_domain_early.hpp> |
| 14 | +#include <beman/execution26/detail/default_domain.hpp> |
| 15 | +#include <beman/execution26/detail/make_sender.hpp> |
| 16 | +#include <beman/execution26/detail/product_type.hpp> |
| 17 | +#include <beman/execution26/detail/sender_for.hpp> |
| 18 | +#include <beman/execution26/detail/join_env.hpp> |
| 19 | +#include <beman/execution26/detail/forward_like.hpp> |
| 20 | +#include <beman/execution26/detail/fwd_env.hpp> |
| 21 | +#include <beman/execution26/detail/sched_env.hpp> |
| 22 | +#include <beman/execution26/detail/starts_on.hpp> |
| 23 | +#include <beman/execution26/detail/continues_on.hpp> |
| 24 | +#include <beman/execution26/detail/write_env.hpp> |
| 25 | +#include <utility> |
| 26 | + |
| 27 | +#include <beman/execution26/detail/suppress_push.hpp> |
| 28 | + |
| 29 | +// ---------------------------------------------------------------------------- |
| 30 | + |
| 31 | +namespace beman::execution26::detail { |
| 32 | +struct on_t : ::beman::execution26::sender_adaptor_closure<on_t> { |
| 33 | + template <::beman::execution26::detail::sender_for<on_t> OutSndr, typename Env> |
| 34 | + auto transform_env(OutSndr&& out_sndr, Env&& env) const -> decltype(auto) { |
| 35 | + auto&& data{out_sndr.template get<1>()}; |
| 36 | + |
| 37 | + if constexpr (::beman::execution26::scheduler<decltype(data)>) |
| 38 | + return ::beman::execution26::detail::join_env( |
| 39 | + ::beman::execution26::detail::sched_env(::beman::execution26::detail::forward_like<OutSndr>(data) |
| 40 | + |
| 41 | + ), |
| 42 | + ::beman::execution26::detail::fwd_env(::std::forward<Env>(env))); |
| 43 | + else |
| 44 | + return std::forward<Env>(env); |
| 45 | + } |
| 46 | + |
| 47 | + template <typename> |
| 48 | + struct env_needs_get_scheduler { |
| 49 | + using sender_concept = ::beman::execution26::sender_t; |
| 50 | + template <typename Env> |
| 51 | + auto get_completion_signatures(Env&&) const { |
| 52 | + return env_needs_get_scheduler<Env>{}; |
| 53 | + } |
| 54 | + }; |
| 55 | + |
| 56 | + template <::beman::execution26::detail::sender_for<on_t> OutSndr, typename Env> |
| 57 | + auto transform_sender(OutSndr&& out_sndr, Env&& env) const -> decltype(auto) { |
| 58 | + struct not_a_scheduler {}; |
| 59 | + auto&& [_, data, child] = out_sndr; |
| 60 | + |
| 61 | + if constexpr (::beman::execution26::scheduler<decltype(data)>) { |
| 62 | + auto sch{::beman::execution26::detail::query_with_default( |
| 63 | + ::beman::execution26::get_scheduler, env, not_a_scheduler{})}; |
| 64 | + if constexpr (::std::same_as<not_a_scheduler, decltype(sch)>) { |
| 65 | + return env_needs_get_scheduler<Env>{}; |
| 66 | + } else { |
| 67 | + return ::beman::execution26::continues_on( |
| 68 | + ::beman::execution26::starts_on(::beman::execution26::detail::forward_like<OutSndr>(data), |
| 69 | + ::beman::execution26::detail::forward_like<OutSndr>(child)), |
| 70 | + ::std::move(sch)); |
| 71 | + } |
| 72 | + } else { |
| 73 | + auto& [sch, closure] = data; |
| 74 | + auto orig_sch{::beman::execution26::detail::query_with_default( |
| 75 | + ::beman::execution26::get_completion_scheduler<::beman::execution26::set_value_t>, |
| 76 | + ::beman::execution26::get_env(child), |
| 77 | + ::beman::execution26::detail::query_with_default( |
| 78 | + ::beman::execution26::get_scheduler, env, not_a_scheduler{}))}; |
| 79 | + |
| 80 | + if constexpr (::std::same_as<not_a_scheduler, decltype(orig_sch)>) { |
| 81 | + return env_needs_get_scheduler<Env>{}; |
| 82 | + } else { |
| 83 | + return ::beman::execution26::detail::write_env( |
| 84 | + ::beman::execution26::continues_on( |
| 85 | + ::beman::execution26::detail::forward_like<OutSndr>(closure)( |
| 86 | + ::beman::execution26::continues_on( |
| 87 | + ::beman::execution26::detail::write_env( |
| 88 | + ::beman::execution26::detail::forward_like<OutSndr>(child), |
| 89 | + ::beman::execution26::detail::sched_env(orig_sch)), |
| 90 | + sch)), |
| 91 | + orig_sch), |
| 92 | + ::beman::execution26::detail::sched_env(env)); |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + template <::beman::execution26::scheduler Sch, ::beman::execution26::sender Sndr> |
| 98 | + requires ::beman::execution26::detail::is_sender_adaptor_closure<Sndr> |
| 99 | + auto operator()(Sch&&, Sndr&&) const -> void = |
| 100 | + BEMAN_EXECUTION26_DELETE("on(sch, sndr) requires that sndr isn't both a sender and sender adaptor closure"); |
| 101 | + |
| 102 | + template <::beman::execution26::scheduler Sch, |
| 103 | + ::beman::execution26::sender Sndr, |
| 104 | + ::beman::execution26::detail::is_sender_adaptor_closure Closure> |
| 105 | + requires ::beman::execution26::detail::is_sender_adaptor_closure<Sndr> |
| 106 | + auto operator()(Sndr&&, Sch&&, Closure&&) const -> void = |
| 107 | + BEMAN_EXECUTION26_DELETE("on(sch, sndr) requires that sndr isn't both a sender and sender adaptor closure"); |
| 108 | + |
| 109 | + template <::beman::execution26::scheduler Sch, ::beman::execution26::sender Sndr> |
| 110 | + auto operator()(Sch&& sch, Sndr&& sndr) const { |
| 111 | + auto domain{::beman::execution26::detail::query_with_default( |
| 112 | + ::beman::execution26::get_domain, sch, ::beman::execution26::default_domain{})}; |
| 113 | + return ::beman::execution26::transform_sender( |
| 114 | + domain, |
| 115 | + ::beman::execution26::detail::make_sender(*this, ::std::forward<Sch>(sch), ::std::forward<Sndr>(sndr))); |
| 116 | + } |
| 117 | + template <::beman::execution26::scheduler Sch, |
| 118 | + ::beman::execution26::sender Sndr, |
| 119 | + ::beman::execution26::detail::is_sender_adaptor_closure Closure> |
| 120 | + auto operator()(Sndr&& sndr, Sch&& sch, Closure&& closure) const { |
| 121 | + auto domain{::beman::execution26::detail::get_domain_early(sndr)}; |
| 122 | + return ::beman::execution26::transform_sender( |
| 123 | + domain, |
| 124 | + ::beman::execution26::detail::make_sender( |
| 125 | + *this, |
| 126 | + ::beman::execution26::detail::product_type{::std::forward<Sch>(sch), ::std::forward<Closure>(closure)}, |
| 127 | + ::std::forward<Sndr>(sndr))); |
| 128 | + } |
| 129 | + template <::beman::execution26::scheduler Sch, ::beman::execution26::detail::is_sender_adaptor_closure Closure> |
| 130 | + auto operator()(Sch&& sch, Closure&& closure) const { |
| 131 | + return ::beman::execution26::detail::sender_adaptor{ |
| 132 | + *this, ::std::forward<Sch>(sch), ::std::forward<Closure>(closure)}; |
| 133 | + } |
| 134 | +}; |
| 135 | + |
| 136 | +#if 0 |
| 137 | +template <typename Data, typename Sender, typename Env> |
| 138 | +struct completion_signatures_for_impl< |
| 139 | + ::beman::execution26::detail::basic_sender<::beman::execution26::detail::on_t, Data, Sender>, |
| 140 | + Env> { |
| 141 | + //-dk:TODO pick up scheduler errors and merge them in? |
| 142 | + using type = |
| 143 | +#if 0 |
| 144 | + ::beman::execution26::detail::meta::combine< |
| 145 | + ::beman::execution26::completion_signatures_of_t<Sender, Env>, |
| 146 | + ::beman::execution26::completion_signatures<::beman::execution26::set_error_t(::std::exception_ptr)> |
| 147 | + > |
| 148 | +#else |
| 149 | + ::beman::execution26::completion_signatures< |
| 150 | + ::beman::execution26::set_value_t(), |
| 151 | + ::beman::execution26::set_error_t(::std::exception_ptr) |
| 152 | + > |
| 153 | +#endif |
| 154 | + ; |
| 155 | +}; |
| 156 | +#endif |
| 157 | + |
| 158 | +} // namespace beman::execution26::detail |
| 159 | + |
| 160 | +namespace beman::execution26 { |
| 161 | +using on_t = ::beman::execution26::detail::on_t; |
| 162 | +inline constexpr ::beman::execution26::on_t on{}; |
| 163 | +} // namespace beman::execution26 |
| 164 | + |
| 165 | +// ---------------------------------------------------------------------------- |
| 166 | + |
| 167 | +#include <beman/execution26/detail/suppress_pop.hpp> |
| 168 | + |
| 169 | +#endif |
0 commit comments