-
Notifications
You must be signed in to change notification settings - Fork 595
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
returning synchronous array in c++ addon #194
Comments
I think you likely want to use a ThreadSafe Function to pass data back to the main thread each time you want to send data |
@mhdawson It worked like you said. but it took sometime for me get familiarized with what Threadsafe Functions are and how to implement them. |
@mhdawson I have a question, can we still use the Threadsafe function using only C addon, i.e include <node_api.h> and not <napi.h> and thus not relying on C++ classes like Napi:Function, Napi:Value , and so on? thank you for the help! |
I think you can use the Threadsafe APIs in C, @gabrielschulhof do you know if we have any examples of that? |
@mhdawson Thanks, I found a Threadsafe example in C. But I have a question: I want to do two callbacks as opposed to one in the javascript callback, Like this: test.startThread((theprime) =>{ (I'm using Node-RED to send a message across) Is this possible ? because we're only calling one callback: size_t argc = 1; Thanks already for your help |
@mhdawson Nevermind I used the curly braces (javascript newbie here) |
good to hear you have what you need. Can this be closed? |
@mhdawson Yes, I will close it now. |
@mhdawson I have a small problem occuring related to the same code, would really appreciate your help. I followed the example of a [async_work_thread_safe_function], and my code is successfully sending arrays of number of elements up to 6, however, when I increase the number of elements of the array being sent the program crashes, I will attach the code that will make the problem clearer. The arrays are real-time recorded data from an osciloscope. Do you think I can't send more than 6 each time because the code can't catch up with the osciloscope because a lot of processing is involved and I shall reduce the number of array elements?
|
When you say crashed do you mean a SIGSEGV or running out of memory? Off the top of my head I can't see why more than 6 would be a problem. |
Hello everyone,
I have a c++ code that I'm using nan to be able to implement it in nodejs environment. The problem is, my code has an while loop and wants to send an array for each loop to the nodejs, but I can only send one array in the addon with args.GetReturnValue.Set() or info.GetReturnValue.Set(). Is there a way to continously send data rather than just returning one value at the end of the addon?
Appreciating any help.
The text was updated successfully, but these errors were encountered: