3232
3333namespace beman ::task::detail {
3434
35- #if 0
36- template <typename T>
37- struct has_exception_ptr;
38- template <typename... T>
39- struct has_exception_ptr<::beman::execution::completion_signatures<T...>> {
40- static constexpr bool value{
41- ::beman::execution::detail::meta::contains<::beman::execution::set_error_t(::std::exception_ptr), T...>};
42- };
43-
44- template <typename T>
45- inline constexpr bool has_exception_ptr_v{::beman::task::detail::has_exception_ptr<T>::value};
46-
47- template <typename Coroutine, typename T, typename C>
48- struct promise_type : ::beman::task::detail::promise_base<::beman::task::detail::stoppable::yes,
49- ::std::remove_cvref_t<T>,
50- ::beman::task::detail::error_types_of_t<C>>,
51- ::beman::task::detail::allocator_support<::beman::task::detail::allocator_of_t<C>> {
52-
53- void start([[maybe_unused]] auto&& e, ::beman::task::detail::state_base<C>* s) {
54- this->state = s;
55- if constexpr (std::same_as<::beman::task::detail::inline_scheduler, scheduler_type>) {
56- this->scheduler.emplace();
57- } else {
58- this->scheduler.emplace(::beman::execution::get_scheduler(e));
59- }
60- this->initial->run();
61- }
62-
63- struct initial_base {
64- virtual ~initial_base() = default;
65- virtual void run() = 0;
66- };
67- struct initial_sender {
68- using sender_concept = ::beman::execution::sender_t;
69- using completion_signatures = ::beman::execution::completion_signatures<::beman::execution::set_value_t()>;
70-
71- template <::beman::execution::receiver Receiver>
72- struct state : initial_base {
73- using operation_state_concept = ::beman::execution::operation_state_t;
74- promise_type* promise;
75- Receiver receiver;
76- template <typename R>
77- state(promise_type* p, R&& r) : promise(p), receiver(::std::forward<R>(r)) {}
78- void start() & noexcept { this->promise->initial = this; }
79- void run() override { ::beman::execution::set_value(::std::move(receiver)); }
80- };
81-
82- promise_type* promise{};
83- template <::beman::execution::receiver Receiver>
84- auto connect(Receiver&& receiver) {
85- return state<::std::remove_cvref_t<Receiver>>(this->promise, ::std::forward<Receiver>(receiver));
86- }
87- };
88-
89- auto initial_suspend() noexcept {
90- return this->internal_await_transform(initial_sender{this},
91- optional_ref_scheduler<scheduler_type>{&this->scheduler});
92- }
93- void unhandled_exception() {
94- if constexpr (::beman::task::detail::has_exception_ptr_v<::beman::task::detail::error_types_of_t<C>>) {
95- this->set_error(std::current_exception());
96- } else {
97- std::terminate();
98- }
99- }
100- auto get_return_object() noexcept { return Coroutine(::beman::task::detail::handle<promise_type>(this)); }
101-
102- template <typename E>
103- auto await_transform(::beman::task::detail::with_error<E> with) noexcept {
104- // This overload is only used if error completions use `co_await with_error(e)`.
105- return std::move(with);
106- }
107- template <typename Env, typename P>
108- auto await_transform(::beman::task::detail::awaiter<Env, P>&& a) noexcept {
109- return ::std::move(a);
110- }
111- template <::beman::execution::sender Sender, typename Scheduler>
112- auto internal_await_transform(Sender&& sender, Scheduler&& sched) noexcept {
113- if constexpr (std::same_as<::beman::task::detail::inline_scheduler, scheduler_type>)
114- return ::beman::execution::as_awaitable(std::forward<Sender>(sender), *this);
115- else
116- return ::beman::execution::as_awaitable(
117- ::beman::task::affine_on(::std::forward<Sender>(sender), ::std::forward<Scheduler>(sched)), *this);
118- }
119- template <::beman::execution::sender Sender>
120- auto await_transform(Sender&& sender) noexcept {
121- return this->internal_await_transform(::std::forward<Sender>(sender), *this->scheduler);
122- }
123- auto await_transform(::beman::task::detail::change_coroutine_scheduler<scheduler_type> c) {
124- return ::std::move(c);
125- }
126-
127- [[no_unique_address]] allocator_type allocator;
128- std::optional<scheduler_type> scheduler{};
129- ::beman::task::detail::state_base<C>* state{};
130- initial_base* initial{};
131-
132- std::coroutine_handle<> unhandled_stopped() {
133- this->state->complete();
134- return std::noop_coroutine();
135- }
136-
137-
138- auto get_env() const noexcept -> env_t { return env_t{this}; }
139- };
140- #else
141-
142- template <typename Coroutine, typename T, typename Environment>
35+ template <typename Coroutine, typename Value, typename Environment>
14336class promise_type
144- : public ::beman::task::detail::promise_base<::beman::task::detail::stoppable::yes,
145- ::std::remove_cvref_t <T>,
146- ::beman::task::detail::error_types_of_t <Environment>>,
37+ : public ::beman::task::detail::
38+ promise_base<::beman::task::detail::stoppable::yes, ::std::remove_cvref_t <Value>, Environment>,
14739 public ::beman::task::detail::allocator_support<::beman::task::detail::allocator_of_t <Environment>> {
14840 public:
14941 using allocator_type = ::beman::task::detail::allocator_of_t <Environment>;
@@ -165,7 +57,7 @@ class promise_type
16557
16658 auto unhandled_exception () noexcept { /* -dk:TODO*/ }
16759 std::coroutine_handle<> unhandled_stopped () {
168- this ->state ->complete ();
60+ this ->get_state () ->complete ();
16961 return std::noop_coroutine ();
17062 }
17163
@@ -192,31 +84,33 @@ class promise_type
19284
19385 template <typename E>
19486 auto yield_value (with_error<E> with) noexcept -> ::beman::task::detail::final_awaiter {
195- this ->set_error (::std::move (with.error ));
87+ this ->get_state ()-> set_error (::std::move (with.error ));
19688 return {};
19789 }
19890
19991 auto get_env () const noexcept -> ::beman::task::detail::promise_env<promise_type> { return {this }; }
20092
201- auto start (::beman::task::detail::state_base<Environment>* state) -> ::std::coroutine_handle<> {
93+ auto start (::beman::task::detail::state_base<Value, Environment>* state) -> ::std::coroutine_handle<> {
20294 ::beman::task::detail::logger l (" promise_type::start" );
203- this ->state = state ;
95+ this ->set_state ( state) ;
20496 return ::std::coroutine_handle<promise_type>::from_promise (*this );
20597 }
206- auto notify_complete () -> ::std::coroutine_handle<> { return this ->state ->complete (); }
207- scheduler_type change_scheduler (scheduler_type other) { return this ->state ->set_scheduler (::std::move (other)); }
98+ auto notify_complete () -> ::std::coroutine_handle<> { return this ->get_state ()->complete (); }
99+ scheduler_type change_scheduler (scheduler_type other) {
100+ return this ->get_state ()->set_scheduler (::std::move (other));
101+ }
208102
209- auto get_scheduler () const noexcept -> scheduler_type { return this ->state ->get_scheduler (); }
103+ auto get_scheduler () const noexcept -> scheduler_type { return this ->get_state () ->get_scheduler (); }
210104 auto get_allocator () const noexcept -> allocator_type { return this ->allocator ; }
211- auto get_stop_token () const noexcept -> stop_token_type { return this ->state ->get_stop_token (); }
212- auto get_context () const noexcept -> const Environment& { return this ->state -> get_context (); }
105+ auto get_stop_token () const noexcept -> stop_token_type { return this ->get_state () ->get_stop_token (); }
106+ auto get_environment () const noexcept -> const Environment& { return this ->get_state ()-> get_environment (); }
213107
214108 private:
215- allocator_type allocator{};
216- ::std::optional<scheduler_type> scheduler{};
217- ::beman::task::detail::state_base<Environment>* state{};
109+ using env_t = ::beman::task::detail::promise_env<promise_type>;
110+
111+ allocator_type allocator{};
112+ ::std::optional<scheduler_type> scheduler{};
218113};
219- #endif
220114} // namespace beman::task::detail
221115
222116// ----------------------------------------------------------------------------
0 commit comments