What is the execution sequence when one node has multi wires to other nodes?

image

I am so confused, like this pic, one input, four wires, what is the order of node 1, 2, 3, 4?

Hi and welcome to the forum.

I don't think there is any order. The message is just sent to the 4 other nodes.

There is some kind of order, but not in the "normal" way of thinking.

node-red runs on nodejs, which uses an eventloop that is single threaded and handles "events" one by one, so there is a very small delay between each of the messages.

thanks, but as we know, node js is single thread, so there must be a order.
I guess it depends on the order of the wires. For this, first wire connects node 2, and node 2 log firstly.


Hi @DaisyLoveU & welcome to the forum.

Yes. But don't rely on that. Instead change your mindset :slight_smile:

For example: what do you really gain by knowing this? It's an implementation detail that doesn't really help that much once you get used to the event based flow paradigm tbh.

My suggestion is to just go with the flow like a twig on the shoulders of a mighty stream. (Sorry I couldn't resist)

Can I ask, are you just trying out node-red or do you have a project in mind? We can certainly help with advice if you need it.

@DaisyLoveU
According to my own experience, it all depends on the wiring order. If you wire them in numerical order, the messages will be sent in that same order.

@Steve-Mcl
I had to inject 200+ messages (in sequence) in an OPC-UA node, each one of them with a particular nodeID, so I could poll it and get everything back. Instead of using so many inject nodes, I used a single inject node, and a subflow with a lot of OPCUA-Item nodes so each of them would add a single nodeID to the polling list. All those nodes were in parallel, arranged by modules, and wired in sequence, so when I convert the resulting array from the poll, all the parameters are arranged in order.

I know it is not necessary and that it would work regardless of how I wire them, but I just like to have the object with the parameters ordered by module and theme, since it's easier for a human to debug and follow than if they're just randomly arranged:

1 Like

Thanks a lot for ur answer, it really helps me learn the deep principle of Node-red!

As @Steve-Mcl pointed out, it is usually irrelevant because nodes are triggered when a message comes and not earlier.

However, if you have a use case similar to the one I mentioned, where you need a lot of messages arriving in a short period of time to a node (for configuration, for instance), knowing this comes in handy because you can just wire everything in parallel and sequentially, and node-red will process the input one after the other in its main loop, with no delays in between.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.