Evaluate all trigger conditions before executing any actions. #7920
Labels
2027
2027 target
component: command-based
WPILib Command Based Library
type: bug
Something isn't working.
Uh oh!
There was an error while loading. Please reload this page.
see [CD thread] (https://www.chiefdelphi.com/t/trigger-condition-evaluation/500280)
Describe the bug
The EventLoop evaluates Triggers in insertion order. Early trigger actions can affect the antecedents of later trigger evaluations, which can have surprising effects: imagine there are two triggers on the same condition, but the first one resets the condition: the second one will never run. This is easy to see in a trigger-driven "state machine" -- one of the common triggers involves state matching, and one of the common actions is to change the state.
To Reproduce
Here's the example I posted on CD.
Here’s an example of the bad thing, which chains the “exit foo” event in a way that it is never seen (i.e. the “B” never appears):
Here’s an example that seems better, with “on enter” and “on exit” events separately bound. It's not equivalent, but for most uses, it's probably better anyway?
Expected behavior
I would expect all the conditions to be evaluated before any actions are executed. This wouldn't completely solve the problem -- imagine conditions with condition-modifying side effects -- but I bet if you write a condition with a side effect, you really know what you're doing. sigh. const.
Additional context
The most obvious way to fix this, to me, is to change EventLoop considerably (so it uses some sort of task object instead of Runnable), but EventLoop is used all over. There could be a new thing, just for Triggers.
Another option is to just document the behavior, and come back to this topic in 2027, or something.
Eh?
The text was updated successfully, but these errors were encountered: