Sequence in operation

Hi,
I try with difficulty to improve my code and so sometimes I have probably banal questions to propose you.
In my node-red project I have many delay node (and I'd like to reduce them) because I always put them between two function when in the second function I need to read the value of a variable set in the previous function.

Example:
I use many node chronos scheduler ...

flow

node configuration

chronos

code flow

code

Well, the delay is necessary or independently by the complexity of the function previous (the example in very simple but is not always the case) the node chronos will always be able to read the flow variable also without the delay?

I can't see the value of the delay node in the example you give above.

Your function and scheduler nodes are not both running at the same time.
The scheduler node will do nothing until a message arrives at it's input.
The function first sets flow.hour_timer and then sends msg.

So the delay just provides a window in which flow.hour_timer could be reset by another run (instance? iteration?) of the function or by some other part of the flow, presumably before it is used.

Ok,
the instruction

flow.set("hour_timer", orario);

is performed before the

return msg;

Not simultaneously at the end of the function, as I thought ....

To be honest I don't know how individual actions within a function node are sequenced, but I assume that "return msg" is not executed until "flow.set...." is complete.

I am sure though that the scheduler node will do nothing until after the function node sends a message, regardless of a delay node.

Is flow.hour_timer only there to pass a value to the scheduler node? Although I am not familiar with the scheduler node, I assume you could use a property of the message. For example, in the function msg.hour_timer = orario; and refer to msg.hour_timer in the scheduler.

Ok, thank you ....

I don't see the need for the delay node. The scheduler node reads the content from the flow context variable at flow deployment (so if the variable is not yet existing then, which is the case if you use memory-based variables, the node will run into an error) and everytime it gets refreshed via the input message (either enable or reload command). At that time, the timers will be (re)started.

1 Like

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