diff --git a/libs/pika/execution/include/pika/execution/algorithms/let_value.hpp b/libs/pika/execution/include/pika/execution/algorithms/let_value.hpp index 74092974e..60e1d2a7b 100644 --- a/libs/pika/execution/include/pika/execution/algorithms/let_value.hpp +++ b/libs/pika/execution/include/pika/execution/algorithms/let_value.hpp @@ -120,7 +120,7 @@ namespace pika::let_value_detail { // Operation state from connecting predecessor sender to // let_value_predecessor_receiver - predecessor_operation_state_type predecessor_op_state; + std::optional predecessor_op_state; using predecessor_ts_type = pika::util::detail::prepend_t< predecessor_value_types, @@ -158,12 +158,14 @@ namespace pika::let_value_detail { { pika::execution::experimental::set_error( PIKA_MOVE(r.receiver), PIKA_FORWARD(Error, error)); + r.op_state.predecessor_op_state.reset(); } friend void tag_invoke(pika::execution::experimental::set_stopped_t, let_value_predecessor_receiver&& r) noexcept { pika::execution::experimental::set_stopped(PIKA_MOVE(r.receiver)); + r.op_state.predecessor_op_state.reset(); }; struct start_visitor @@ -238,6 +240,7 @@ namespace pika::let_value_detail { op_state.predecessor_ts .template emplace...>>( PIKA_FORWARD(Ts, ts)...); + // op_state.predecessor_op_state.reset(); pika::detail::visit( set_value_visitor{PIKA_MOVE(receiver), PIKA_MOVE(f), op_state}, op_state.predecessor_ts); @@ -266,10 +269,12 @@ namespace pika::let_value_detail { template operation_state(PredecessorSender_&& predecessor_sender, Receiver_&& receiver, F_&& f) - : predecessor_op_state{pika::execution::experimental::connect( - PIKA_FORWARD(PredecessorSender_, predecessor_sender), - let_value_predecessor_receiver( - PIKA_FORWARD(Receiver_, receiver), PIKA_FORWARD(F_, f), *this))} + : predecessor_op_state(pika::detail::with_result_of([&]() { + return pika::execution::experimental::connect( + PIKA_FORWARD(PredecessorSender_, predecessor_sender), + let_value_predecessor_receiver( + PIKA_FORWARD(Receiver_, receiver), PIKA_FORWARD(F_, f), *this)); + })) { } @@ -281,7 +286,7 @@ namespace pika::let_value_detail { friend void tag_invoke( pika::execution::experimental::start_t, operation_state& os) noexcept { - pika::execution::experimental::start(os.predecessor_op_state); + pika::execution::experimental::start(*os.predecessor_op_state); } };