asio icon indicating copy to clipboard operation
asio copied to clipboard

Added error_as_deferred.

Open klemens-morgenstern opened this issue 2 years ago • 1 comments

Heya Chris,

I had an idea: make error_code & exception_ptr completion tokens, so that the following is legal:

asio::steady_timer tim{co_await asio::this_coro::executor};
asio::error_code ec;

co_await tim.async_wait(ec);

This would make this much more intuitive because it looks like the sync APIs.

klemens-morgenstern avatar Jul 09 '22 14:07 klemens-morgenstern

I think the usefulness of this feature is more evident in the context of awaitable operators, for example, this is a code snipet in my project

      boost::system::error_code ec1, ec2;
      co_await (
         conn->async_run(ep, {}, net::redirect_error(net::use_awaitable, ec1)) &&
         conn->async_exec(req, adapt(), net::redirect_error(net::use_awaitable, ec2))
      );

which is annoyingly verbose. I would have prefered to write

      boost::system::error_code ec1, ec2;
      co_await (conn->async_run(ep, {}, ec1) && conn->async_exec(req, adapt(), ec2));

mzimbres avatar Oct 07 '22 20:10 mzimbres