@@ -46,20 +46,23 @@ struct awaiter_op_t<Awaiter, ParentPromise, false> {
4646};
4747
4848template <typename Value, typename Env, typename OwnPromise, typename ParentPromise>
49- class awaiter : public ::beman::task::detail::state_base<Value, Env>,
50- ::beman::task::detail::state_rep<Env, ::beman::task::detail::handle<OwnPromise>> {
49+ class awaiter : public ::beman::task::detail::state_base<Value, Env> {
5150 public:
5251 using stop_token_type = typename ::beman::task::detail::state_base<Value, Env>::stop_token_type;
5352 using scheduler_type = typename ::beman::task::detail::state_base<Value, Env>::scheduler_type;
5453
55- explicit awaiter (::beman::task::detail::handle<OwnPromise> h)
56- : ::beman::task::detail::state_rep<Env, ::beman::task::detail::handle<OwnPromise>>(std::move(h)) {}
54+ explicit awaiter (::beman::task::detail::handle<OwnPromise> h) : handle(std::move(h)) {}
5755 constexpr auto await_ready () const noexcept -> bool { return false ; }
58- auto await_suspend (::std::coroutine_handle<ParentPromise> parent) noexcept {
56+ struct env_receiver {
57+ ParentPromise* parent;
58+ auto get_env () const noexcept { return parent->get_env (); }
59+ };
60+ auto await_suspend (::std::coroutine_handle<ParentPromise> parent) noexcept {
61+ this ->state_rep .emplace (env_receiver{&parent.promise ()});
5962 this ->scheduler .emplace (
6063 this ->template from_env <scheduler_type>(::beman::execution::get_env (parent.promise ())));
6164 this ->parent = ::std::move (parent);
62- return this ->receiver .start (this );
65+ return this ->handle .start (this );
6366 }
6467 auto await_resume () { return this ->result_resume (); }
6568
@@ -82,20 +85,20 @@ class awaiter : public ::beman::task::detail::state_base<Value, Env>,
8285 return this ->actual_complete ();
8386 }
8487 auto actual_complete () -> std::coroutine_handle<> {
85- return this ->::beman::task::detail::state_base<Value, Env>::no_completion_set ()
86- ? this ->parent .promise ().unhandled_stopped ()
87- : ::std::move (this ->parent );
88+ return this ->no_completion_set () ? this ->parent .promise ().unhandled_stopped () : ::std::move (this ->parent );
8889 }
8990 auto do_get_scheduler () -> scheduler_type override { return *this ->scheduler ; }
9091 auto do_set_scheduler (scheduler_type other) -> scheduler_type override {
9192 return ::std::exchange (*this ->scheduler , other);
9293 }
9394 auto do_get_stop_token () -> stop_token_type override { return {}; }
94- auto do_get_environment () -> Env& override { return this ->context ; }
95+ auto do_get_environment () -> Env& override { return this ->state_rep -> context ; }
9596
96- ::std::optional<scheduler_type> scheduler;
97- ::std::coroutine_handle<ParentPromise> parent{};
98- ::std::optional<awaiter_op_t <awaiter, ParentPromise>> reschedule{};
97+ ::beman::task::detail::handle<OwnPromise> handle;
98+ ::std::optional<::beman::task::detail::state_rep<Env, env_receiver>> state_rep;
99+ ::std::optional<scheduler_type> scheduler;
100+ ::std::coroutine_handle<ParentPromise> parent{};
101+ ::std::optional<awaiter_op_t <awaiter, ParentPromise>> reschedule{};
99102};
100103} // namespace beman::task::detail
101104
0 commit comments