Add comments to runner state machine reaction functions

To make it a little more obvious what each function is
responsible for doing (and why) add comments onto each
inner reaction function that explains more of its purpose
in life.

Change-Id: Ibdb55e873e4b1ae5675e2f50d85ac0ecbd59ffb6
This commit is contained in:
Joshua Harlow
2015-01-23 14:45:24 -08:00
parent cfe478a2bc
commit 66fc2df3a6

View File

@@ -99,11 +99,19 @@ class _MachineBuilder(object):
timeout = _WAITING_TIMEOUT
def resume(old_state, new_state, event):
# This reaction function just updates the state machines memory
# to include any nodes that need to be executed (from a previous
# attempt, which may be empty if never ran before) and any nodes
# that are now ready to be ran.
memory.next_nodes.update(self._completer.resume())
memory.next_nodes.update(self._analyzer.get_next_nodes())
return _SCHEDULE
def game_over(old_state, new_state, event):
# This reaction function is mainly a intermediary delegation
# function that analyzes the current memory and transitions to
# the appropriate handler that will deal with the memory values,
# it is *always* called before the final state is entered.
if memory.failures:
return _FAILED
if self._analyzer.get_next_nodes():
@@ -114,6 +122,11 @@ class _MachineBuilder(object):
return _REVERTED
def schedule(old_state, new_state, event):
# This reaction function starts to schedule the memory's next
# nodes (iff the engine is still runnable, which it may not be
# if the user of this engine has requested the engine/storage
# that holds this information to stop or suspend); handles failures
# that occur during this process safely...
if self.runnable() and memory.next_nodes:
not_done, failures = self._scheduler.schedule(
memory.next_nodes)
@@ -136,6 +149,11 @@ class _MachineBuilder(object):
return _ANALYZE
def analyze(old_state, new_state, event):
# This reaction function is responsible for analyzing all nodes
# that have finished executing and completing them and figuring
# out what nodes are now ready to be ran (and then triggering those
# nodes to be scheduled in the future); handles failures that
# occur during this process safely...
next_nodes = set()
while memory.done:
fut = memory.done.pop()