Hi everyone,
I'm working on a native addon and from inside an AsyncWorker I need to call a function, in the specific I want call the function in the Execute method and I know that it's not possible. I want know if there's a simple way to do that and if my need is correlated with the following issue on n-api
https://github.com/nodejs/node/pull/17887
Thanks
If you want to call into JS from another thread, then you definitely need
https://github.com/nodejs/node/pull/17887.
On Tue, Mar 20, 2018 at 12:35 PM, Nicola Del Gobbo <[email protected]
wrote:
Hi everyone,
I'm working on a native addon and from inside an AsyncWorker I need to
call a function, in the specific I want call the function in the Execute
method and I know that it's not possible. I want know if there's a simple
way to do that and if my need is correlated with the following issue on
n-api
nodejs/node#17887 https://github.com/nodejs/node/pull/17887
Thanks—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/nodejs/node-addon-api/issues/241, or mute the thread
https://github.com/notifications/unsubscribe-auth/AA7k0aLaBtcCkEKq5lrH_zx7QygBr5-jks5tgS_bgaJpZM4SyPVg
.
@gabrielschulhof Thank you for your quickly answer.
@gabrielschulhof Today I tried to call a JavaScript function from the Execute method of an AsyncWorker using uv_async_init and uv_async_send. All seems to work, but I'm asking if the runtime is capable to well track my function call. What do you think?
In the uv_async_cb on the loop thread you need a HandleScope followed by
a CallbackScope before you can call into JS.
@NickNaso, Can you share an example of calling NAPI methods in the Execute function?
Thanks. :)
@jasonrsadler the only N-API methods you can call from the Execute() function are the ones dealing with thread-safe functions. I don't believe those are covered by node-addon-api, so you would have to use them directly.
Thanks @gabrielschulhof. Could I bother you to show me a quick example?
@jasonrsadler https://github.com/gabrielschulhof/abi-stable-node-addon-examples/tree/tsfn_async_work/async_work_thread_safe_function/node-api provides an example with plain N-API.
Most helpful comment
@jasonrsadler https://github.com/gabrielschulhof/abi-stable-node-addon-examples/tree/tsfn_async_work/async_work_thread_safe_function/node-api provides an example with plain N-API.