cplusplus / sender-receiver

Issues list for P2300
Apache License 2.0
19 stars 3 forks source link

Specification of `let_value`, `let_error`, etc. should not use receiver composition in `receiver2` definition #231

Closed lewissbaker closed 3 months ago

lewissbaker commented 4 months ago

The current wording of let_value, let_error, let_stopped defines a recevier2 type that is intended to be connected to the sender returned from invoking the Fn with the result of the first sender.

As currently defined, the receiver2 holds as a base-class sub-object, the receiver passed to connect() on the let_value sender. The motivation here being that the child operation can just directly call the parent receiver's completion signal.

However, this is problematic in the case that connect() on the child operation fails with an exception. The let_value operation must move-construct the receiver into the receiver2 object and then pass that receiver2 object into the connect() call on the second sender.

However, if that connect() call exits with an exception, then the let_value operation now needs to complete the operation as a whole with set_error(), but cannot because the receiver that needs to receive the result is now in a moved-from state.

Instead, we should store the parent receiver in the operation-state and then have receiver2 hold a pointer to the operation state. That way, if we end up discarding receiver2 due to the child connect() all throwing an exception, then we still have a way to call the parent receiver.

ericniebler commented 3 months ago

fixed in R10