Skip to content

Commit

Permalink
Capture shared_ptr of this
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertIndie committed Jan 15, 2024
1 parent dfb71df commit 2e00353
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/ConsumerImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1508,25 +1508,26 @@ void ConsumerImpl::hasMessageAvailableAsync(HasMessageAvailableCallback callback

if (messageId == MessageId::latest()) {
lock.unlock();
getLastMessageIdAsync([this, callback](Result result, const GetLastMessageIdResponse& response) {
auto self = get_shared_this_ptr();
getLastMessageIdAsync([self, callback](Result result, const GetLastMessageIdResponse& response) {
if (result != ResultOk) {
callback(result, {});
return;
}
auto handleResponse = [this, response, callback] {
auto handleResponse = [self, response, callback] {
if (response.hasMarkDeletePosition() && response.getLastMessageId().entryId() >= 0) {
// We only care about comparing ledger ids and entry ids as mark delete position doesn't
// have other ids such as batch index
auto compareResult = compareLedgerAndEntryId(response.getMarkDeletePosition(),
response.getLastMessageId());
callback(ResultOk, this->config_.isStartMessageIdInclusive() ? compareResult <= 0
callback(ResultOk, self->config_.isStartMessageIdInclusive() ? compareResult <= 0
: compareResult < 0);
} else {
callback(ResultOk, false);
}
};
if (this->config_.isStartMessageIdInclusive()) {
this->seekAsync(response.getLastMessageId(), [callback, handleResponse](Result result) {
if (self->config_.isStartMessageIdInclusive()) {
self->seekAsync(response.getLastMessageId(), [callback, handleResponse](Result result) {
if (result != ResultOk) {
callback(result, {});
return;
Expand Down

0 comments on commit 2e00353

Please sign in to comment.