TL;DR How can a long-running thread call a JS function repeatedly, i.e. without the use of AsyncWorker?
AsyncWorker seems to be for one long-running task that calls back to JS land only once, once finished.
In my scenario, a background thread is repeatedly calling back to JS land, something like relaying events that occur in native land to a JS callback. In the past (node.js 0.8), I did this with libuv's uv_async_send(), but I need to upgrade, and since uv and v8 have changed so much I thought I'd migrate straight over to node-addon-api, as it seems to have everything I need.
However I cannot seem to find out how to pull this off with AsyncContext and CallbackScope, which are made for cases like this, if I parse the docs correctly. However, all examples in the documentation and the tests in https://github.com/nodejs/node-addon-api/blob/master/test/ for both classes are (ironically?) working synchronously, and my attempts to migrate their callbacks over to run on a different thread have failed so far.
A nudge in the right direction on how to change either test/asyncworker.cc, test/callbackscope.cc or https://github.com/nodejs/node-addon-api/blob/master/doc/async_context.md#example to work asynchronously would be awesome. If I do get it to work in a reasonable amount of time, I promise I'll add a test and/or an example to node-addon-api.
(In order to be run on the JS thread, I'd expect I'd have to provide something like a function pointer, but I can't find anything to that effect in AsyncContext, CallbackScope, or Function::MakeCallback)
TL;DR How can a long-running thread call a JS function repeatedly, i.e. without the use of
AsyncWorker?AsyncWorkerseems to be for one long-running task that calls back to JS land only once, once finished.In my scenario, a background thread is repeatedly calling back to JS land, something like relaying events that occur in native land to a JS callback. In the past (node.js 0.8), I did this with libuv's
uv_async_send(), but I need to upgrade, and since uv and v8 have changed so much I thought I'd migrate straight over to node-addon-api, as it seems to have everything I need.However I cannot seem to find out how to pull this off with
AsyncContextandCallbackScope, which are made for cases like this, if I parse the docs correctly. However, all examples in the documentation and the tests in https://github.com/nodejs/node-addon-api/blob/master/test/ for both classes are (ironically?) working synchronously, and my attempts to migrate their callbacks over to run on a different thread have failed so far.A nudge in the right direction on how to change either
test/asyncworker.cc,test/callbackscope.ccor https://github.com/nodejs/node-addon-api/blob/master/doc/async_context.md#example to work asynchronously would be awesome. If I do get it to work in a reasonable amount of time, I promise I'll add a test and/or an example to node-addon-api.(In order to be run on the JS thread, I'd expect I'd have to provide something like a function pointer, but I can't find anything to that effect in AsyncContext, CallbackScope, or Function::MakeCallback)