Matt-Esch commented on a change in pull request #200: URL: https://github.com/apache/pulsar-client-node/pull/200#discussion_r831660197
########## File path: src/Consumer.cc ########## @@ -79,144 +81,131 @@ void MessageListener(pulsar_consumer_t *cConsumer, pulsar_message_t *cMessage, v listenerCallback->callback.Release(); } -void Consumer::SetCConsumer(std::shared_ptr<CConsumerWrapper> cConsumer) { this->wrapper = cConsumer; } -void Consumer::SetListenerCallback(ListenerCallback *listener) { +void Consumer::SetCConsumer(std::shared_ptr<pulsar_consumer_t> cConsumer) { this->cConsumer = cConsumer; } +void Consumer::SetListenerCallback(MessageListenerCallback *listener) { if (listener) { + // Pass consumer as argument + listener->consumer = this; + } + + if (this->listener == nullptr) { // Maintain reference to consumer, so it won't get garbage collected // since, when we have a listener, we don't have to maintain reference to consumer (in js code) this->Ref(); Review comment: The reference counter should not be incremented if the message listener is not set. This only gets called in the constructor of the Consumer if there is a listener. All this change does is ensure that if someone were to call this in future from somewhere else the references would remain balanced. I will add a check to make sure that the listener being set isn't itself nullptr. The change just makes the code more resilient rather than changing any actual behaviour. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org