Boost C++ 库

...世界上最受推崇和专业设计的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ 编码标准

PrevUpHomeNext

dispatch(3 个重载中的 2 个)

提交一个完成令牌或函数对象以供执行。

template<
    typename Executor,
    typename NullaryToken = default_completion_token_t<Executor>>
auto dispatch(
    const Executor & ex,
    NullaryToken && token = default_completion_token_t< Executor >(),
    constraint_t< execution::is_executor< Executor >::value||is_executor< Executor >::value >  = 0);

此函数提交一个对象,以便使用指定的执行器执行。函数对象可能会在从 dispatch() 返回之前从当前线程调用。否则,它将被排队等待执行。

参数

ex

目标执行器。

token

将用于生成完成处理程序的完成令牌。完成处理程序的函数签名必须是

void handler();
返回值

此函数返回 async_initiate<NullaryToken, void()>(Init{ex}, token),其中 Init 是定义为如下的函数对象类型

class Init
{
public:
  using executor_type = Executor;
  explicit Init(const Executor& ex) : ex_(ex) {}
  executor_type get_executor() const noexcept { return ex_; }
  template <typename CompletionHandler>
    void operator()(CompletionHandler&& completion_handler) const;
private:
  Executor ex_; // exposition only
};

Init: 的函数调用运算符:

完成签名
void()

PrevUpHomeNext