Avoiding race conditions on flow start

Let's consider I have two generic processes being triggered on flow start and I want to withhold message(s) from one of them (Process 2) until some condition calculated by the other (Process 1) is met, and then pass all messages intact and with no delay.

I could withhold a message with either delay, trigger, or join node, but then I would need to do it for every message, not only the initial one.

With delay I thought of modifying the delay through msg.delay but I would need to add it to all messages except for the first one, and I end up with a requirement to move the logic ahead.

With trigger and join I could merge two messages (either with msg.reset or msg.complete), but then it would be required for each and every message.


Another idea: use context to store a Boolean value to distinguish between the first and subsequent messages - but then on flow restart, I would need to manually clear the context and thus have a third contender in the initial race.

I could add another Boolean to mark "context cleared", but this gets ugly.

Similarly, I tried adding a trust_level to Process 1 and Process 2 messages and use a simple condition in function, but then I need to use context and have the same problem with clearing.


Whatever I think of, gets patchy and ugly, and I am stuck in some dead-end street with ideas.

Isn't there a clean way to achieve the above?

Could you make use of node-red-contrib-queue-gate in the 'Process 1' flow.
Set the 'default state' as closed, then open the gate via the condition from 'Process 2'?
'Process 1's messages would be queued, and then released.

3 Likes

A real gem. :partying_face: Exactly what I was looking for!

Thank you

1 Like

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