Make sure the deffered objects stay in scope when we call into callback in tagger.

This commit is contained in:
aljar 2021-05-12 15:09:25 +02:00
parent 0d2ea8aa72
commit c2e0cc57eb
1 changed files with 12 additions and 6 deletions

View File

@ -60,9 +60,11 @@ void Tagger::onAck(uint64_t deliveryTag, bool multiple)
if (!_close || unacknowledged()) return;
// close the channel, and forward the callbacks to the installed handler
// we need to be sure the the deffered object stays alive even if the callback
// decides to remove us.
_implementation->close()
.onSuccess([this]() { _close->reportSuccess(); })
.onError([this](const char *message) { _close->reportError(message); });
.onSuccess([this]() { auto close = _close; close->reportSuccess(); })
.onError([this](const char *message) { auto close = _close; close->reportError(message); });
}
/**
@ -76,9 +78,11 @@ void Tagger::onNack(uint64_t deliveryTag, bool multiple)
if (!_close || unacknowledged()) return;
// close the channel, and forward the callbacks to the installed handler
// we need to be sure the the deffered object stays alive even if the callback
// decides to remove us.
_implementation->close()
.onSuccess([this]() { _close->reportSuccess(); })
.onError([this](const char *message) { _close->reportError(message); });
.onSuccess([this]() { auto close = _close; close->reportSuccess(); })
.onError([this](const char *message) { auto close = _close; close->reportError(message); });
}
/**
@ -164,9 +168,11 @@ Deferred &Tagger::close()
if (unacknowledged()) return *_close;
// there are no open messages, we can close the channel directly.
// we need to be sure the the deffered object stays alive even if the callback
// decides to remove us.
_implementation->close()
.onSuccess([this]() { _close->reportSuccess(); })
.onError([this](const char *message) { _close->reportError(message); });
.onSuccess([this]() { auto close = _close; close->reportSuccess(); })
.onError([this](const char *message) { auto close = _close; close->reportError(message); });
// return the created deferred
return *_close;