-
-
Notifications
You must be signed in to change notification settings - Fork 517
[Query] Native callback to addon layer and from there to javascript layer. #756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello @kkoopa , |
Most likely the |
Hello @kkoopa , If you understand my query, following I am trying to acheive, which is a very general scenario:
To achieve this do i have to use some libuv functions [ asynworker ] like you have demonstrated here: Basically my C++ library is pub/sub library: so, my C++ library subscriber side will be receiving events from socket and as addon layer will register a callback to it, it will be receiving event .. As you specified in last comment: But in async_pi_estimate you have commented this:
I got confused whether in my addon layer callback i can access the V8 object and call the javascript callback. Can you give me suggestions for how can i acheive my scenario as I have already tried many ways. |
You cannot access V8 during AsyncWorker::Execute, which is the routine that does the actual work. After this completes, either HandleOkCallback or HandleErrorCallback will be invoked. There you can use V8 again and call back to javascript. The test suite contains many more examples. You might want to buffer events in a queue: |
@kkoopa ,
If I pass addonCallback to the native [C++ library] layer and i receive the callback [Which i am getting currently]. |
Based on my understanding of your setup, that is correct. V8 may only be accessed from the main thread. That is why AsyncWorker stores input and output in the object and then sends output back to V8 from the main thread.
…On March 21, 2018 5:04:29 PM GMT+02:00, Jay Sharma ***@***.***> wrote:
@kkoopa ,
If i understood correctly, I can not access V8 in my class function
which i passed to native layer.
So,
```
Class AddonClass
{
public:
AddonClass() {}
static addonCallback(AddonClass *pointer) {}
....................
};
```
If I pass addonCallback to the native layer and i receive the callback
[Which i am getting currently].
As per you comment I can not call the javascript callback from my
addonCallback function although I have the class object?
|
@kkoopa ,
Please read the deails of addoncallback and let me know if any other details are required. |
No. |
Uh oh!
There was an error while loading. Please reload this page.
I am new to Native addon concept. I am using NAN to build my native addon.
Following are my layers:
I have some query regarding callback mechanism:
Native C++ class
Addon class
I tried the follwing:
Define a static function in addon layer and pass it to the native cpp layer.
Result:
I am getting the native callback in my addon layer. But when i am trying to call it to javascript using :
void AddonClass::addonCallback(AddonClass *pointer) //This object is maintained using std::bind
{
}
When i added Nan::HandleScope scope before getting the handle it is also crashing.
Did i missed anything?
Is it necessary to use libuv library function for storing the addon handle and then to call the callbacks in javascript layer?
Note: I am trying to use event emmiter concept for giving the callbacks to javascript layer
Thanks in advance.
The text was updated successfully, but these errors were encountered: