44#ifndef INCLUDED_INCLUDE_BEMAN_TASK_DETAIL_PROMISE_TYPE
55#define INCLUDED_INCLUDE_BEMAN_TASK_DETAIL_PROMISE_TYPE
66
7+ #include < beman/task/detail/awaiter.hpp>
78#include < beman/task/detail/affine_on.hpp>
89#include < beman/task/detail/allocator_of.hpp>
910#include < beman/task/detail/allocator_support.hpp>
2021#include < beman/task/detail/with_error.hpp>
2122#include < beman/execution/execution.hpp>
2223#include < beman/execution/detail/meta_contains.hpp>
24+ #include < cassert>
2325#include < coroutine>
2426#include < optional>
2527#include < type_traits>
28+ #include < beman/task/detail/logger.hpp>
2629
2730// ----------------------------------------------------------------------------
2831
32+ namespace beman ::task::detail {
33+
34+ #if 0
2935struct opt_rcvr {
3036 using receiver_concept = ::beman::execution::receiver_t;
3137 void set_value(auto&&...) && noexcept {}
3238 void set_error(auto&&) && noexcept {}
3339 void set_stopped() && noexcept {}
3440};
3541
36- namespace beman ::task::detail {
37-
3842template <typename T>
3943struct has_exception_ptr;
4044template <typename... T>
@@ -186,6 +190,10 @@ struct promise_type : ::beman::task::detail::promise_base<::beman::task::detail:
186190 // This overload is only used if error completions use `co_await with_error(e)`.
187191 return std::move(with);
188192 }
193+ template <typename Env, typename P>
194+ auto await_transform(::beman::task::detail::awaiter<Env, P>&& a) noexcept {
195+ return ::std::move(a);
196+ }
189197 template <::beman::execution::sender Sender, typename Scheduler>
190198 auto internal_await_transform(Sender&& sender, Scheduler&& sched) noexcept {
191199 if constexpr (std::same_as<::beman::task::detail::inline_scheduler, scheduler_type>)
@@ -223,14 +231,15 @@ struct promise_type : ::beman::task::detail::promise_base<::beman::task::detail:
223231 return std::noop_coroutine();
224232 }
225233
226- struct env {
234+ struct env_t {
227235 const promise_type* promise;
228236
229237 scheduler_type query(::beman::execution::get_scheduler_t) const noexcept { return *promise->scheduler; }
230238 allocator_type query(::beman::execution::get_allocator_t) const noexcept { return promise->allocator; }
231239 stop_token_type query(::beman::execution::get_stop_token_t) const noexcept {
232240 return promise->state->get_stop_token();
233241 }
242+ auto foo() const {} //-dk:TODO remove
234243 template <typename Q, typename... A>
235244 requires requires(const C& c, Q q, A&&... a) {
236245 ::beman::execution::forwarding_query(q);
@@ -241,8 +250,53 @@ struct promise_type : ::beman::task::detail::promise_base<::beman::task::detail:
241250 }
242251 };
243252
244- env get_env () const noexcept { return {this }; }
253+ auto get_env() const noexcept -> env_t { return env_t {this}; }
245254};
255+ #else
256+ template <typename Coroutine, typename T, typename Environment>
257+ class promise_type
258+ : public ::beman::task::detail::promise_base<::beman::task::detail::stoppable::yes,
259+ ::std::remove_cvref_t <T>,
260+ ::beman::task::detail::error_types_of_t <Environment>>,
261+ public ::beman::task::detail::allocator_support<::beman::task::detail::allocator_of_t <Environment>> {
262+ public:
263+ struct final_awaiter {
264+ ::beman::task::detail::state_base<Environment>* state{};
265+ constexpr auto await_ready () const noexcept -> bool { return false ; }
266+ auto await_suspend (auto &&) noexcept -> ::std::coroutine_handle<> {
267+ ::beman::task::detail::logger l (" promise_type::final_awaiter::await_suspend()" );
268+ return this ->state ->complete ();
269+ }
270+ constexpr auto await_resume () noexcept -> void {}
271+ };
272+ constexpr auto initial_suspend () noexcept -> ::std::suspend_always {
273+ ::beman::task::detail::logger l (" promise_type::initial_suspend" );
274+ return {};
275+ }
276+ constexpr auto final_suspend () noexcept -> final_awaiter {
277+ ::beman::task::detail::logger l (" promise_type::final_suspend" );
278+ assert (this ->state != nullptr );
279+ return {this ->state };
280+ }
281+
282+ auto unhandled_exception () noexcept { /* -dk:TODO*/ }
283+ auto get_return_object () noexcept { return Coroutine (::beman::task::detail::handle<promise_type>(this )); }
284+
285+ struct env {};
286+ auto get_env () const noexcept { return env{}; }
287+
288+ auto start (::beman::task::detail::state_base<Environment>* state) -> ::std::coroutine_handle<> {
289+ ::beman::task::detail::logger l (" promise_type::start" );
290+ this ->state = state;
291+ assert (this ->state != nullptr );
292+ return ::std::coroutine_handle<promise_type>::from_promise (*this );
293+ }
294+
295+ private:
296+ ::beman::task::detail::logger l{" promise_type" };
297+ ::beman::task::detail::state_base<Environment>* state{};
298+ };
299+ #endif
246300} // namespace beman::task::detail
247301
248302// ----------------------------------------------------------------------------
0 commit comments