7#include <boost/asio.hpp>
8#if defined(BOOST_ASIO_HAS_CO_AWAIT)
9#include <boost/asio/experimental/awaitable_operators.hpp>
12#include "common/common.hpp"
14namespace net = boost::asio;
15namespace resp3 = aedis::resp3;
16using namespace net::experimental::awaitable_operators;
17using steady_timer = net::use_awaitable_t<>::as_default_on_t<net::steady_timer>;
37auto receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
39 using resp_type = std::vector<resp3::node<std::string>>;
40 for (resp_type resp;;) {
41 co_await conn->async_receive(
adapt(resp));
42 std::cout << resp.at(1).value <<
" " << resp.at(2).value <<
" " << resp.at(3).value << std::endl;
47auto co_main(std::string host, std::string port) -> net::awaitable<void>
49 auto ex =
co_await net::this_coro::executor;
50 auto conn = std::make_shared<connection>(ex);
51 steady_timer timer{ex};
55 req.
push(
"SUBSCRIBE",
"channel");
59 co_await connect(conn, host, port);
60 co_await ((conn->async_run() || healthy_checker(conn) || receiver(conn)) && conn->async_exec(req));
63 timer.expires_after(std::chrono::seconds{1});
64 co_await timer.async_wait();
void push(std::string_view cmd, Ts const &... args)
Appends a new command to the end of the request.
auto adapt(std::size_t max_read_size=(std::numeric_limits< std::size_t >::max)()) noexcept
Creates an adapter that ignores responses.