cplusplus / sender-receiver

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

the preconditions on `run_loop::run()` are too strict #280

Open ericniebler opened 1 month ago

ericniebler commented 1 month ago

problem

the precondition on run_loop::run() is that the state is starting. given that run_loop::finish() puts the loop in the finishing state, the implication is that one cannot call finish() before calling run().

However, in most cases sync_wait is calling finish() on its run_loop before calling run(), violating this precondition. sync_wait does the following:

run_loop loop;
auto op = connect(sndr, sync_wait_receiver{&loop});
start(op);

loop.run();

if sndr completes synchronously, the sync_wait_receiver will call finish() on the loop before loop.run() is called, violating run's precondition.

proposed resolution

the precondition on run_loop::run should be:

  1. Precondition: state is starting or finishing.
lewissbaker commented 1 month ago

I don't think that the proposed resolution is sufficient as this doesn't prevent the case where run() has previously been called and has returned.

Assuming we want to preserve this restriction (i.e. you can only call run() once), we probably want to instead: