@@ -299,8 +299,47 @@ class MetadataWorker : public Napi::AsyncWorker {
299299 Metadata_return result_;
300300};
301301
302+ //
303+ // Worker 8: CloseRows asynchronously
304+ //
305+ class CloseRowsWorker : public Napi ::AsyncWorker {
306+ public:
307+ CloseRowsWorker (Napi::Function& callback, int64_t poolId, int64_t connId, int64_t rowsId)
308+ : AsyncWorker(callback), poolId_(poolId), connId_(connId), rowsId_(rowsId), result_({0 , 0 , 0 , 0 , nullptr }) {}
309+
310+ void Execute () override {
311+ result_ = ::CloseRows (poolId_, connId_, rowsId_);
312+ }
313+
314+ void OnOK () override {
315+ Napi::Env env = Env ();
316+ Napi::Object obj = Napi::Object::New (env);
317+ obj.Set (" r0" , Napi::Number::New (env, result_.r0 ));
318+ obj.Set (" r1" , Napi::Number::New (env, result_.r1 ));
319+ obj.Set (" r2" , Napi::Number::New (env, result_.r2 ));
320+ obj.Set (" r3" , Napi::Number::New (env, result_.r3 ));
321+ if (result_.r4 != nullptr && result_.r3 > 0 ) {
322+ obj.Set (" r4" , Napi::Buffer<uint8_t >::Copy (env, (uint8_t *)result_.r4 , result_.r3 ));
323+ } else {
324+ obj.Set (" r4" , env.Null ());
325+ }
326+ // Release the pinner ID of the response message to prevent native leak!
327+ if (result_.r0 > 0 ) {
328+ ::Release (result_.r0);
329+ }
330+ Callback ().Call ({env.Null (), obj});
331+ }
332+ private:
333+ int64_t poolId_, connId_, rowsId_;
334+ CloseRows_return result_;
335+ };
336+
302337Napi::Value MetadataWrapper (const Napi::CallbackInfo& info) {
303338 Napi::Env env = info.Env ();
339+ if (info.Length () < 4 ) {
340+ Napi::Error::New (env, " MetadataWrapper requires 4 arguments" ).ThrowAsJavaScriptException ();
341+ return env.Null ();
342+ }
304343 int64_t pid = info[0 ].As <Napi::Number>().Int64Value ();
305344 int64_t cid = info[1 ].As <Napi::Number>().Int64Value ();
306345 int64_t rid = info[2 ].As <Napi::Number>().Int64Value ();
@@ -323,21 +362,17 @@ Napi::Value NativeRelease(const Napi::CallbackInfo& info) {
323362// CloseRows dummy/missing implementation for POC length if needed, or we just rely on GC.
324363Napi::Value CloseRowsWrapper (const Napi::CallbackInfo& info) {
325364 Napi::Env env = info.Env ();
326- if (info.Length () < 3 ) return env.Null ();
365+ if (info.Length () < 4 ) {
366+ Napi::Error::New (env, " CloseRowsWrapper requires 4 arguments" ).ThrowAsJavaScriptException ();
367+ return env.Null ();
368+ }
327369 int64_t pid = info[0 ].As <Napi::Number>().Int64Value ();
328370 int64_t cid = info[1 ].As <Napi::Number>().Int64Value ();
329371 int64_t rid = info[2 ].As <Napi::Number>().Int64Value ();
372+ Napi::Function cb = info[3 ].As <Napi::Function>();
330373
331- // N-API sync close implementation
332- CloseRows (pid, cid, rid);
333-
334- // invokeAsync appends a callback at the end of properties
335- if (info.Length () >= 4 && info[3 ].IsFunction ()) {
336- Napi::Object obj = Napi::Object::New (env);
337- obj.Set (" r1" , Napi::Number::New (env, 0 ));
338- Napi::Function cb = info[3 ].As <Napi::Function>();
339- cb.Call ({env.Null (), obj}); // Mock empty GoReturnTuple callback
340- }
374+ CloseRowsWorker* worker = new CloseRowsWorker (cb, pid, cid, rid);
375+ worker->Queue ();
341376 return env.Undefined ();
342377}
343378
0 commit comments