std::execution::ensure_started

来自cppreference.com
< cpp‎ | execution
 
 
 
在标头 <execution> 定义
execution::sender auto ensure_started( execution::sender auto sender );
(C++26 起)

参数

sender-输入发送器,其停止通道映射到 err

返回值

返回一个发送器,于所提供的 sender 完成时完成,并产生等价于所提供的 sender 所产生的值。

注解

  • 一旦 ensure_started 返回,即可知所提供的 sender 已经连接,且已在所产生的操作状态上调用了 start。换言之,已将所提供的 sender 所描述的工作提交给相应执行资源予以执行。
  • 如果所返回的发送器在调用 execution::connect() 前被销毁,或如果调用了 execution::connect() 但所返回的操作状态在调用 execution::start() 前被销毁,则向急切发起的操作发送一个停止请求,并且这个操作被脱离并将在背景中运行直至完成。
  • 这种情况下,在该操作最终完成时将会丢弃其结果。
  • 注意,应用程序将需要确保操作脱离的情况中的各项资源持续存活(如通过持有到这些资源的 std::shared_ptr)。