Messages not being received in the debug node untill the native addon has finished sending all messages

Hello Node-RED community,

I am importing a C++ addon into my Node-RED to send samples from my Analog Discovery 2 device into Node-RED using NAPI. The C++ code basically sends samples from the device to Node-RED using event emitter for each sample sent. The sampling rate is 500 samples/seconds. I can see in the Node-RED window the metric info that the function acutally sends messages upon receiving from the addon each second to Node-RED, but later on after all the samples has been sent (2mins) can see the debug node starting to receive those messages and showing them. I am interested in signal real-time analysis so that's why I would like that the messages get sent upon receiving simultaneously and shown in the debug node (or sent to another node for further simultaneous processing)
. I read about the Asynchronous behaviour of Node-RED that's expected it to work the way I want. I tried using node.done() after each node.send(msg) and also wrapping it in a new node, but the same occurs. Is there a way to let this work simultaneously?
Thanks so much for any helpers.

const EventEmitter = require('events');

const test = require('C:/directory/build/Release/addon');

const emitter = new EventEmitter();
var a;
emitter.on('something',(evt)=>{ a=(evt);msg.payload=a;node.send(msg);node.done();})
test.Hello(emitter.emit.bind(emitter));

Use node.warn(value) before node.send, to see the value just in time before value is sent.

1 Like

Thanks for the reply, I am also interested in further processing of the message in a later node, so I am interested that the message is received in the next node simultaneously.

For the warn function, it also showed the values after all the sending was done.

I think I cant help you further. I even do not know if this is possible at all. As far as I know - Node Red is working single threaded , so even async processing will not be processed in parallel. But I think a developer of NR has to respond to your request.

1 Like