hrsakai commented on a change in pull request #153:
URL: https://github.com/apache/pulsar-client-node/pull/153#discussion_r634015655



##########
File path: src/Reader.cc
##########
@@ -176,13 +228,31 @@ class ReaderCloseWorker : public Napi::AsyncWorker {
  private:
   Napi::Promise::Deferred deferred;
   pulsar_reader_t *cReader;
+  Reader *reader;
 };
 
 Napi::Value Reader::Close(const Napi::CallbackInfo &info) {
   Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(info.Env());
-  ReaderCloseWorker *wk = new ReaderCloseWorker(deferred, this->cReader);
+  ReaderCloseWorker *wk = new ReaderCloseWorker(deferred, 
this->wrapper->cReader, this);
   wk->Queue();
   return deferred.Promise();
 }
 
-Reader::~Reader() { pulsar_reader_free(this->cReader); }
+void Reader::Cleanup() {
+  if (this->listener) {
+    this->CleanupListener();
+  }
+}
+
+void Reader::CleanupListener() {
+  this->Unref();
+  this->listener->callback.Release();
+  this->listener = nullptr;
+}
+
+Reader::~Reader() {
+  if (this->listener) {
+    this->CleanupListener();
+  }
+  pulsar_reader_free(this->wrapper->cReader);

Review comment:
       Can we delete this line because `pulsar_reader_free` is executed on 
`CReaderWrapper::~CReaderWrapper`?




-- 
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to