Flow branching - Execution Sequence

I have a flow that branches at a certain point.

From reading in various sources, I have understood that the sequence of execution is somewhat depending on two factors:

  • Asynchronous event loop of node.js
  • Sequence of how the individual nodes have been wired

Now I need to make sure that "Branch 1" returns before "Branch 2" and I would appreciate any input how to secure this.

Node-RED isn't really strong in this area - as you say, due to the async nature of JavaScript.

You could try:

  • Buld in a delay to branch 2 - maybe a timeout function (in a function node) that checks for a variable set in branch 1.
  • Put both branches into a function node and use JavaScript promises to enforce the order.

or - don't spit them... run them in sequence...

1 Like

Many thanks for returning. I'll try to avoid branching.

Nevertheless, I think the fact that the execution priority is pretty much unpredictable adds an additional layer of complexity. Like in this case, for flows that need to pass some decision gates that in turn depend on processes in other parts of the flow.

Some means to control this would be nice.

Anyway, I'm a big time NR fan. Keep up the great work!

Often you can use a Join node to solve these problems. Where a flow must wait for inputs from multiple streams you can use a Join node in key pair mode so that the next action does not proceed till all inputs are satisfied.