33 Execution control library [exec]

33.9 Senders [exec.snd]

33.9.12 Sender adaptors [exec.adapt]

33.9.12.17 Exposition-only std​::​execution​::​stop-when [exec.stop.when]

stop-when fuses an additional stop token t into a sender so that, upon connecting to a receiver r, the resulting operation state receives stop requests from both t and the token returned from get_stop_token(get_env(r)).
The name stop-when denotes an exposition-only sender adaptor.
For subexpressions sndr and token:
  • If decltype((sndr)) does not satisfy sender, or remove_cvref_t<decltype((token))> does not satisfy stoppable_token, then stop-when(sndr, token) is ill-formed.
  • Otherwise, if remove_cvref_t<decltype((token))> models unstoppable_token then stop-when(​sndr, token) is expression-equivalent to sndr.
  • Otherwise, stop-when(sndr, token) returns a sender osndr.
    If osndr is connected to a receiver r, let rtoken be the result of get_stop_token(get_env(r)).
    • If the type of rtoken models unstoppable_token then the effects of connecting osndr to r are equivalent to connect(write_env(sndr, prop(get_stop_token, token)), r).
    • Otherwise, the effects of connecting osndr to r are equivalent to connect(write_env(sndr, prop(get_stop_token, stoken)), r) where stoken is an object of an exposition-only type stoken-t such that:
      • stoken-t models stoppable_token;
      • stoken.stop_requested() returns token.stop_requested() || rtoken.stop_reques-
        ted()
        ;
      • stoken.stop_possible() returns token.stop_possible() || rtoken.stop_possible(); and
      • for types Fn and Init such that both invocable<Fn> and constructible_from<Fn, Init> are modeled, stoken-t​::​callback_type<Fn> models stoppable-callback-for<Fn, stoken-t, Init>.
        [Note 1: 
        For an object fn of type Fn constructed from a value, init, of type Init, registering fn using stoken-t​::​callback_type<Fn>(stoken, init) results in an invocation of fn when a callback registered with token or rtoken would be invoked.
        fn is invoked at most once.
        — end note]