mireo / async-mqtt5

A C++17 MQTT client based on Boost.Asio.
https://spacetime.mireo.com/async-mqtt5/
Boost Software License 1.0
154 stars 11 forks source link

executor_type/get_executor #11

Closed klemens-morgenstern closed 3 months ago

klemens-morgenstern commented 4 months ago

With boost 1.86 some tokens (namely cancel_at and cancel_after) and the partial tokens use the associated_executor from the initiation object. This allows the following:

c.async_publish<async_mqtt5::qos_e::at_most_once>(
        "<topic>", "Hello world!",
        async_mqtt5::retain_e::no, async_mqtt5::publish_props {},
        asio::cancel_after([&c](async_mqtt5::error_code ec) {
            std::cout << ec.message() << std::endl;
            c.async_disconnect(boost::asio::detached); // disconnect and close the client
        }, std::chrono::milliseconds(100)));
    );

it will also allow partial tokens, e.g. the following:

auto [ec] = co_await c.async_publish<async_mqtt5::qos_e::at_most_once>(
        "<topic>", "Hello world!",
        async_mqtt5::retain_e::no, async_mqtt5::publish_props {}, asio::as_tuple);

std::cout << ec.message() << std::endl;
ksimicevic commented 3 months ago

Resolved with 40b1f7e00cb861a5b8d6b97dda148ed965792b19.