Skip to content

Commit 35cfdae

Browse files
committed
Unifies the signatures of async functions.
1 parent 3a74575 commit 35cfdae

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ auto co_main(config const& cfg) -> net::awaitable<void>
5454
response<std::string> resp;
5555

5656
// Executes the request.
57-
co_await conn->async_exec(req, resp, net::deferred);
57+
co_await conn->async_exec(req, resp);
5858
conn->cancel();
5959

6060
std::cout << "PING: " << std::get<0>(resp).value() << std::endl;
@@ -98,7 +98,7 @@ receiver(std::shared_ptr<connection> conn) -> net::awaitable<void>
9898
while (conn->will_reconnect()) {
9999
100100
// Reconnect to channels.
101-
co_await conn->async_exec(req, ignore, net::deferred);
101+
co_await conn->async_exec(req, ignore);
102102
103103
// Loop reading Redis pushes.
104104
for (;;) {
@@ -246,14 +246,14 @@ response<
246246
Where both are passed to `async_exec` as showed elsewhere
247247

248248
```cpp
249-
co_await conn->async_exec(req, resp, net::deferred);
249+
co_await conn->async_exec(req, resp);
250250
```
251251
252252
If the intention is to ignore responses altogether use `ignore`
253253
254254
```cpp
255255
// Ignores the response
256-
co_await conn->async_exec(req, ignore, net::deferred);
256+
co_await conn->async_exec(req, ignore);
257257
```
258258

259259
Responses that contain nested aggregates or heterogeneous data
@@ -296,7 +296,7 @@ response<
296296
...
297297
> resp;
298298

299-
co_await conn->async_exec(req, resp, net::deferred);
299+
co_await conn->async_exec(req, resp);
300300
```
301301
302302
Everything else stays pretty much the same.
@@ -336,7 +336,7 @@ response<
336336
exec_resp_type, // exec
337337
> resp;
338338

339-
co_await conn->async_exec(req, resp, net::deferred);
339+
co_await conn->async_exec(req, resp);
340340
```
341341
342342
For a complete example see cpp20_containers.cpp.
@@ -384,7 +384,7 @@ using other types
384384
```cpp
385385
// Receives any RESP3 simple or aggregate data type.
386386
boost::redis::generic_response resp;
387-
co_await conn->async_exec(req, resp, net::deferred);
387+
co_await conn->async_exec(req, resp);
388388
```
389389
390390
For example, suppose we want to retrieve a hash data structure

include/boost/redis/connection.hpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ class basic_connection {
574574
async_run(
575575
config const& cfg = {},
576576
Logger l = Logger{},
577-
CompletionToken token = CompletionToken{})
577+
CompletionToken&& token = {})
578578
{
579579
cfg_ = cfg;
580580
resv_.set_config(cfg);
@@ -612,8 +612,8 @@ class basic_connection {
612612
* bytes.
613613
*/
614614
template <class CompletionToken = asio::default_completion_token_t<executor_type>>
615-
auto async_receive(CompletionToken token = CompletionToken{})
616-
{ return receive_channel_.async_receive(std::move(token)); }
615+
auto async_receive(CompletionToken&& token = {})
616+
{ return receive_channel_.async_receive(std::forward<CompletionToken>(token)); }
617617

618618
/** @brief Receives server pushes synchronously without blocking.
619619
*
@@ -677,7 +677,7 @@ class basic_connection {
677677
async_exec(
678678
request const& req,
679679
Response& resp = ignore,
680-
CompletionToken&& token = CompletionToken{})
680+
CompletionToken&& token = {})
681681
{
682682
return this->async_exec(req, any_adapter(resp), std::forward<CompletionToken>(token));
683683
}
@@ -692,7 +692,7 @@ class basic_connection {
692692
async_exec(
693693
request const& req,
694694
any_adapter adapter,
695-
CompletionToken&& token = CompletionToken{})
695+
CompletionToken&& token = {})
696696
{
697697
auto& adapter_impl = adapter.impl_;
698698
BOOST_ASSERT_MSG(req.get_expected_responses() <= adapter_impl.supported_response_size, "Request and response have incompatible sizes.");
@@ -937,9 +937,9 @@ class basic_connection {
937937
{ return !notifier_.is_open();}
938938

939939
template <class CompletionToken>
940-
auto async_wait(CompletionToken token)
940+
auto async_wait(CompletionToken&& token)
941941
{
942-
return notifier_.async_receive(std::move(token));
942+
return notifier_.async_receive(std::forward<CompletionToken>(token));
943943
}
944944

945945
//private:
@@ -1013,7 +1013,8 @@ class basic_connection {
10131013
return asio::async_compose
10141014
< CompletionToken
10151015
, void(system::error_code)
1016-
>(detail::reader_op<this_type, Logger>{this, l}, token, writer_timer_);
1016+
>(detail::reader_op<this_type, Logger>{this, l},
1017+
std::forward<CompletionToken>(token), writer_timer_);
10171018
}
10181019

10191020
template <class CompletionToken, class Logger>
@@ -1022,7 +1023,7 @@ class basic_connection {
10221023
return asio::async_compose
10231024
< CompletionToken
10241025
, void(system::error_code)
1025-
>(detail::writer_op<this_type, Logger>{this, l}, token, writer_timer_);
1026+
>(detail::writer_op<this_type, Logger>{this, l}, std::forward<CompletionToken>(token), writer_timer_);
10261027
}
10271028

10281029
[[nodiscard]] bool coalesce_requests()
@@ -1252,7 +1253,7 @@ class connection {
12521253

12531254
/// Calls `boost::redis::basic_connection::async_run`.
12541255
template <class CompletionToken = asio::deferred_t>
1255-
auto async_run(config const& cfg, logger l, CompletionToken token = {})
1256+
auto async_run(config const& cfg, logger l, CompletionToken&& token = {})
12561257
{
12571258
return asio::async_initiate<
12581259
CompletionToken, void(boost::system::error_code)>(
@@ -1264,8 +1265,8 @@ class connection {
12641265

12651266
/// Calls `boost::redis::basic_connection::async_receive`.
12661267
template <class CompletionToken = asio::deferred_t>
1267-
auto async_receive(CompletionToken token = {})
1268-
{ return impl_.async_receive(std::move(token)); }
1268+
auto async_receive(CompletionToken&& token = {})
1269+
{ return impl_.async_receive(std::forward<CompletionToken>(token)); }
12691270

12701271
/// Calls `boost::redis::basic_connection::receive`.
12711272
std::size_t receive(system::error_code& ec)

0 commit comments

Comments
 (0)