How do I pass an object of another class as a parameter of a callback function in node-addon-api?
Code Snippet:
#include <napi.h>
#include "Third_Party_Library.h"
using namespace Napi;
class WorkerInit : public AsyncWorker {
public:
WorkerInit(Function &callback) : AsyncWorker(callback) {}
private:
void Execute() {
Third_Party_Library_Init();
}
void OnOK() {
Napi::HandleScope scope(Env());
Callback().Call(
{
Number::New(Env(), 0),
Third_Party_Library_Method()
}
);
}
};
Object Init(Env env, Object exports) {
exports.Set(String::New(env, "init"), Function::New(env, Init));
return exports;
};
NODE_API_MODULE(
module_name,
Init
);
Here I have been trying to execute the code asynchronously. But I am unable to compile the code as it is throwing "no matching member function for call to 'Call' Callback().Call(" error.
I need the return value of Third_Party_Library_Method() in my js script. Is there any way to convert this object into a generic node-addon-api object?
I am kind of new to C++ and any help will be highly appreciated.