Closed jbbjarnason closed 1 week ago
See https://redboltz.github.io/async_mqtt/doc/latest/tutorial/client.html Send MQTT CONNECT packet and start receive loop
See https://redboltz.github.io/async_mqtt/doc/latest/tutorial/client.html Send MQTT CONNECT packet and start receive loop
I am not sure I follow, previously async_send
or send
had completion token for void(std::error_code)
but now it is void()
To be more specific, the return type of this call https://github.com/redboltz/async_mqtt/blob/main/example/ep_cpp20coro_mqtt_client.cpp#L43 previously was std::error_code but now is void.
However async_send
for callable completion token, lambda, has std::error_code completion token, see here: https://github.com/redboltz/async_mqtt/blob/main/example/ep_cb_mqtt_client.cpp#L67
The CompletionToken parameter for async_send() is boost::system::error_code, not void.
The first boost::system::error_code is treated specially. When you use CompletionToken such as use_awaitable
, the first boost::system::error_code is converted to the exception internally and removed from the parameter.
This is asio style. All other asio function do that.
If you don't want to exception, you can fix your code like this:
auto [ec] = co_await ep->async_send(
...,
as::as_tuple(as::use_awaitable)
);
Interesting, did not remember that with asio thanks!!
@jbbjarnason
Yes, at first, I thought it was strange. If the completion token has the signature void(boost::system::error_code ec1, boost::system::error_code ec2)
, then only ec1
is treated specially.
However, after studying Boost.Asio in depth, I found that this convention is designed working well with many other Boost.Asio mechanisms.
previously we could
async_send
with an error_code return variable,example:
now with the following compile error:
But this works with lambdas, I am not sure the callpath is different between those tokens.
Is this supposed to work or was this feature removed?