33 Execution control library [exec]

33.9 Senders [exec.snd]

33.9.1 General [exec.snd.general]

Subclauses [exec.factories] and [exec.adapt] define customizable algorithms that return senders.
Each algorithm has a default implementation.
Let sndr be the result of an invocation of such an algorithm or an object equal to the result ([concepts.equality]), and let Sndr be decltype((sndr)).
Let rcvr be a receiver of type Rcvr with associated environment env of type Env such that sender-to<Sndr, Rcvr> is true.
For the default implementation of the algorithm that produced sndr, connecting sndr to rcvr and starting the resulting operation state ([exec.async.ops]) necessarily results in the potential evaluation ([basic.def.odr]) of a set of completion operations whose first argument is a subexpression equal to rcvr.
Let Sigs be a pack of completion signatures corresponding to this set of completion operations, and let CS be the type of the expression get_completion_signatures<Sndr, Env>().
Then CS is a specialization of the class template completion_signatures ([exec.cmplsig]), the set of whose template arguments is Sigs.
If none of the types in Sigs are dependent on the type Env, then the expression get_completion_signatures<Sndr>() is well-formed and its type is CS.
Each completion operation can potentially be evaluated on one of several different execution agents as determined by the semantics of the algorithm, the environment of the receiver, and the completions of any child senders.
For a completion tag T, let be a pack comprised of the set of domain tags associated with the execution agents that could potentially evaluate any of the operation's completions with tag T.
If there are no potentially evaluated completion operations with tag type T, then get_completion_domain<T>(get_env(sndr), env) is ill-formed; otherwise, it has type COMMON-DOMAIN<...> ([exec.snd.expos]).
[Example 1: 
Let sndr2 be the sender then(sndr, fn).
sndr2 has the same set_value completion domain tag as sndr, but if fn's evaluation is potentially throwing, sndr's set_error completion domain tag would be the COMMON-DOMAIN of sndr's value and error completion domain tags, in accordance with the semantics of the then algorithm ([exec.then]).
— end example]
If sndr can determine that all of its completion operations with tag T happen on execution agents associated with a particular scheduler sch (as determined by the semantics of the algorithm, the environment of the receiver, and the completion schedulers of any child senders), then get_completion_scheduler<T>(get_env(sndr), env) is well-formed and has the type and value of sch; otherwise, it is ill-formed.
[Example 2: 
Let sndr2 be the sender from the example above.
The set_value completion scheduler of sndr2 is the set_value completion scheduler of sndr, if any.
But sndr2 can only report a set_error completion scheduler when invocations of fn are not potentially throwing or when sndr has no set_error completions.
When fn can throw, sndr2 could complete with set_error either by forwarding an error completion from sndr or by completing with the exception thrown by fn, which would happen on an agent associated with sndr's set_value completion scheduler.
— end example]
If a user-provided implementation of the algorithm that produced sndr is selected instead of the default:
  • Any completion signature that is in the set of types denoted by completion_signatures_of_t<Sndr, Env> and that is not part of Sigs shall correspond to error or stopped completion operations, unless otherwise specified.
  • If none of the types in Sigs are dependent on the type Env, then completion_signatures_of_t<Sndr> and completion_signatures_of_t<Sndr, Env> shall denote the same type.
Various function templates in subclause [exec.snd] can throw an exception of type unspecified-exception.
Each such exception object is of an unspecified type such that a handler of type exception matches ([except.handle]) the exception object but a handler of type dependent_sender_error does not.
[Note 1: 
There is no requirement that two such exception objects have the same type.
— end note]