Which io_context does std::boost::asio::post / dispatch use?

 ̄綄美尐妖づ 提交于 2019-12-02 07:48:16

The core of the documentation is found with the associated_executor trait:

  • get()

    If T has a nested type executor_type, returns t.get_executor(). Otherwise returns ex.

  • executor_type

    If T has a nested type executor_type, T::executor_type. Otherwise Executor.

If your handler type¹ has a nested executor_type type, then it is assumed that calling token.get() will return the correct executor to use.

If you pass a vanilla calleable to post without specifying an executor/execution context you will get a default-constructed instance of an execution context: boost::asio::system_executor.

The purpose of this is for the implementation to DoTheRightThing with custom handler types. E.g. if you post something on a strand, the handler will be wrapped in a type specific to the strand implementation. The associated_executor trait and ditto get_executor() member function will then coordinate to direct to the executor for that strand.


¹ or any token, in case your call model is different, like a yield context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!