boost::asio::spawn yield as callback

前端 未结 3 513
终归单人心
终归单人心 2020-12-28 08:57

I\'m trying to rewrite a project using boost::asio::spawn coroutines. Some parts of the project cannot be changed. For example, the storage protocol library is

3条回答
  •  情话喂你
    2020-12-28 09:20


    Great thanks to free_coffe i managed this to work. Posting solution for my case, possibly someone need it.

    template 
    RequestResult async_foo(Packet &pkt, CompletionToken&& token) {
       typename boost::asio::handler_type< CompletionToken, void(RequestResult) >::type handler( std::forward(token) );
      boost::asio::async_result result(handler);
      storage_api->writePacket(pkt, handler);
      return result.get();
    }
    

    Later we can use this proxy:

    RequestResult res = async_foo(pkt, std::forward(yield) );
    

提交回复
热议问题