How to call a reference function asynchronously, from N-api, I can not get "env"!

338 Views Asked by At

js code is:

const obj = tap.create();
quote.on("connection", (params) => {
console.log('[DEBUG js]', 'connection called, params:', params);
});

remember function in c++:

napi_create_reference(env, args[1], 1, &cbMap[eIt->second]);

when native function is called:

void TAP_CDECL Spi::OnConnect(int errorCode, const Info *info) {

{{I want to call the function from cbMap here, How to write code? I do not 
known how to find "env"!}}

}
1

There are 1 best solutions below

0
On

I use node-addon-api solve the problem, now i found napi updated, from https://insight.io/github.com/nodejs/node/tree/master/test/addons-napi/test_env_sharing/, I think it is useful!