Wait until piston is finished from within another piston


#1

I’m executing a piston from within a piston.

My question is, will the host piston wait for the other piston to finish before it continues, or will it continue while the other piston runs? For my purposes, the other piston MUST finish fully before the host piston continues… much like calling a subroutine.
The other piston will assign a global variable that the host piston needs.

eg:

MAIN PISTON
blah
blah
execute piston “SOME_OTHER_PISTON” (must execute fully first… not run in parallel)
blah
blah
blah

SOME_OTHER_PISTON
settings
_ disable automatic piston state;_
end settings;
blah
blah
blah


#2

It will not wait. They run independently.

When I do this, I use the very last command in piston 1 to execute the 2nd piston.
(daisy chain)


If you are passing variables, then I recommend using the External URL.
If you want to pass @globals, then the 2nd piston might want to begin with a 12 sec WAIT before any action is taken.


#3

You can choose to ‘wait for execution’ and the host piston will wait for the callee piston to exit but it does this by running the new instance in the same thread rather like a subroutine.

However a restriction is that ‘exit’ is not necessarily the same as finish. When a piston waits for five seconds or more it exits and a new instance of the piston is launched to continue after the wait, so if a callee piston did that the host piston would get control back at that point.

Also pistons read globals into a cache at startup and write any changes on exit so the host piston would not see changes made by a callee piston unless it itself immediately did a long wait so it exited and restarted and picked up the new value.


#4

In my case, I prefer the result that’s assigned to that global variable. Also, that called piston does some stuff first… in this case wakes my Tesla up, then sets that global var as AWAKE or ASLEEP (as in unreachable). Then the host piston continues and checks that the car is awake and goes on to do it’s thing if it is.

If I have to then I could bite the bullet and merge the two pistons back into one. It’s just I wanted a WAKUP piston, as this is also called in 4 other pistons to save duplicate coding. It also allows the WAKEUP piston to be edited and spares me having to edit the 4 other copies… one in each piston.

I did see the option in the EXECUTE PISTON command to Wait For Execution, but if the global won’t get updated until the next run, then if I want to continue doing what I’m already doing, I would have to just assume the car woke up instead of checking that global var. It’s not the best, but just a tradeoff, unless there’s a better way? One problem is that WAKUP piston attempts to wake the car. If the car is still sleeping, the piton will wait 30sec, then try again for a max of 4 tries. If it still is not awake, then the global var is assigned ASLEEP, and the host piston will not continue.