Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/execution/ensure started"

From cppreference.com
< cpp‎ | execution
(move to cpp/experimental)
m (Reverted edits by Cooky (talk) to last revision by InbalL)
Line 1: Line 1:
 +
{{cpp/execution/title|ensure_started}}
 +
{{cpp/experimental/execution/navbar}}
  
 +
{{fmbox|class=noprint|style=font-size: 0.8em|text='''Note''' This utility is planned to be dropped from P2300 and replaced by {{tt|async_scope}}.}}
 +
 +
{{ddcl|header=execution|since=c++26|
 +
execution::sender auto ensure_started(
 +
    execution::sender auto sender
 +
);
 +
}}
 +
 +
===Parameters===
 +
{{par begin}}
 +
{{par|sender|input sender of which the stopped channel is mapped into {{tt|err}}}}
 +
{{par end}}
 +
 +
===Return value===
 +
Returns a sender which completes when the provided {{c|sender}} completes and sends values equivalent to those of the provided {{c|sender}}.
 +
 +
===Notes===
 +
* Once {{tt|ensure_started}} returns, it is known that the provided {{c|sender}} has been connected and start has been called on the resulting operation state. In other words, the work described by the provided {{c|sender}} has been submitted for execution on the appropriate execution resources.
 +
 +
* If the returned sender is destroyed before {{c|execution::connect()}} is called, or if {{c|execution::connect()}} is called but the returned operation-state is destroyed before {{c|execution::start()}} is called, then a stop-request is sent to the eagerly launched operation and the operation is detached and will run to completion in the background.
 +
 +
* In such a case, the operation's result will be discarded when it is eventually complete.
 +
 +
* Note that the application will need to make sure that resources are kept alive in the case that the operation detaches (e.g. by holding a {{lc|std::shared_ptr}} to those resources).

Revision as of 13:04, 3 October 2024

Defined in header <execution>
execution::sender auto ensure_started(

    execution::sender auto sender

);
(since C++26)

Parameters

sender - input sender of which the stopped channel is mapped into err

Return value

Returns a sender which completes when the provided sender completes and sends values equivalent to those of the provided sender.

Notes

  • Once ensure_started returns, it is known that the provided sender has been connected and start has been called on the resulting operation state. In other words, the work described by the provided sender has been submitted for execution on the appropriate execution resources.
  • If the returned sender is destroyed before execution::connect() is called, or if execution::connect() is called but the returned operation-state is destroyed before execution::start() is called, then a stop-request is sent to the eagerly launched operation and the operation is detached and will run to completion in the background.
  • In such a case, the operation's result will be discarded when it is eventually complete.
  • Note that the application will need to make sure that resources are kept alive in the case that the operation detaches (e.g. by holding a std::shared_ptr to those resources).