2
0
mirror of https://github.com/boostorg/redis.git synced 2026-01-19 04:42:09 +00:00

Makes async_receive2 not cancel on reconnection (#381)

async_receive2 is now only cancelled after calling connection::cancel() or using per-operation cancellation
Adds a restriction to only have one outstanding async_receive2 operation per connection
Adds error::already_running
Adds support for asio::cancel_after for async_receive2
Deprecates cancel(operation::receive)
Adds more documentation to async_receive2

close #331
This commit is contained in:
Anarthal (Rubén Pérez)
2026-01-18 16:14:53 +01:00
committed by GitHub
parent 002b616dd9
commit 89e44dc017
24 changed files with 835 additions and 87 deletions

View File

@@ -117,15 +117,17 @@ auto receiver(std::shared_ptr<connection> conn) -> asio::awaitable<void>
// You're now subscribed to 'mychannel'. Pushes sent over this channel will be stored
// in resp. If the connection encounters a network error and reconnects to the server,
// it will automatically subscribe to 'mychannel' again. This is transparent to the user.
// You need to use specialized request::subscribe() function (instead of request::push)
// to enable this behavior.
// Loop to read Redis push messages.
for (error_code ec;;) {
while (conn->will_reconnect()) {
// Wait for pushes
co_await conn->async_receive2(asio::redirect_error(ec));
auto [ec] = co_await conn->async_receive2(asio::as_tuple);
// Check for errors and cancellations
if (ec && (ec != asio::experimental::error::channel_cancelled || !conn->will_reconnect())) {
std::cerr << "Error during receive2: " << ec << std::endl;
if (ec) {
std::cerr << "Error during receive: " << ec << std::endl;
break;
}