Matt-Esch commented on a change in pull request #200:
URL: https://github.com/apache/pulsar-client-node/pull/200#discussion_r833187982



##########
File path: src/Client.cc
##########
@@ -196,33 +236,27 @@ void LogMessage(pulsar_logger_level_t level, const char 
*file, int line, const c
   logCallback->callback.Release();
 }
 
-class ClientCloseWorker : public Napi::AsyncWorker {
- public:
-  ClientCloseWorker(const Napi::Promise::Deferred &deferred, pulsar_client_t 
*cClient)
-      : AsyncWorker(Napi::Function::New(deferred.Promise().Env(), [](const 
Napi::CallbackInfo &info) {})),
-        deferred(deferred),
-        cClient(cClient) {}
-  ~ClientCloseWorker() {}
-  void Execute() {
-    pulsar_result result = pulsar_client_close(this->cClient);
-    if (result != pulsar_result_Ok) SetError(pulsar_result_str(result));
-  }
-  void OnOK() { this->deferred.Resolve(Env().Null()); }
-  void OnError(const Napi::Error &e) {
-    this->deferred.Reject(
-        Napi::Error::New(Env(), std::string("Failed to close client: ") + 
e.Message()).Value());
-  }
+Napi::Value Client::Close(const Napi::CallbackInfo &info) {
+  auto deferred = ThreadSafeDeferred::New(Env());
+  auto ctx = new ExtDeferredContext<Client *>(this, deferred);
+  this->Ref();
 
- private:
-  Napi::Promise::Deferred deferred;
-  pulsar_client_t *cClient;
-};
+  pulsar_client_close_async(
+      this->cClient.get(),
+      [](pulsar_result result, void *ctx) {
+        auto deferredContext = static_cast<ExtDeferredContext<Client *> 
*>(ctx);

Review comment:
       Nope, good catch I thought I had checked all of these. Not a huge fan of 
having to new/free these but this is a side effect of using the c api I guess.




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


Reply via email to