From 782598d4705f67aa1ada2d783044b9dff9907aa9 Mon Sep 17 00:00:00 2001 From: Marcelo Zimbres Date: Sat, 11 Sep 2021 17:52:39 +0200 Subject: [PATCH] More simplifications. --- examples/async_basic.cpp | 7 ++----- include/aedis/read.hpp | 16 +++++++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/async_basic.cpp b/examples/async_basic.cpp index 945e304f..ffb10235 100644 --- a/examples/async_basic.cpp +++ b/examples/async_basic.cpp @@ -15,15 +15,12 @@ example(net::ip::tcp::socket& socket, std::queue& pipelines) pipelines.push({}); pipelines.back().hello("3"); - std::string buffer; response_buffers buffers; - response_adapters adapters{buffers}; - consumer_state cs; + consumer_state cs{buffers}; for (;;) { auto const type = - co_await async_consume( - socket, buffer, pipelines, adapters, cs, net::use_awaitable); + co_await async_consume(socket, pipelines, cs, net::use_awaitable); if (type == resp3::type::push) { std::cout << "Event: " << "(" << type << ")" << std::endl; diff --git a/include/aedis/read.hpp b/include/aedis/read.hpp index 4c56bab9..698b6fd3 100644 --- a/include/aedis/read.hpp +++ b/include/aedis/read.hpp @@ -355,23 +355,29 @@ struct consume_op { }; struct consumer_state { - net::coroutine coro = net::coroutine(); - resp3::type type = resp3::type::invalid; + std::string buffer; + response_adapters adapters; + net::coroutine coro; + resp3::type type; + + consumer_state(response_buffers& buffers) + : adapters{buffers} + , coro{net::coroutine()} + , type {resp3::type::invalid} + { } }; template auto async_consume( net::ip::tcp::socket& socket, - std::string& buffer, std::queue& pipelines, - response_adapters& adapters, consumer_state& cs, CompletionToken&& token) { return net::async_compose< CompletionToken, void(boost::system::error_code, resp3::type)>( - consume_op{socket, buffer, pipelines, adapters, cs.type, cs.coro}, token, socket); + consume_op{socket, cs.buffer, pipelines, cs.adapters, cs.type, cs.coro}, token, socket); } } // aedis