mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 22:21:32 +00:00
Rename FSMManager handler -> predicate so it actually makes some sense
This commit is contained in:
parent
7e8ea0c7ac
commit
78b689f650
@ -41,22 +41,22 @@ class TFWServer:
|
||||
class FSMManager:
|
||||
def __init__(self, fsm):
|
||||
self._fsm = fsm
|
||||
self.trigger_handlers = defaultdict(list)
|
||||
self.trigger_predicates = defaultdict(list)
|
||||
|
||||
@property
|
||||
def fsm(self):
|
||||
return self._fsm
|
||||
|
||||
def trigger(self, trigger, message):
|
||||
if all((handler() for handler in self.trigger_handlers[trigger])):
|
||||
if all((predicate() for predicate in self.trigger_predicates[trigger])):
|
||||
try: self.fsm.trigger(trigger, message=message)
|
||||
except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger))
|
||||
|
||||
def subscribe_handler(self, trigger, handler):
|
||||
self.trigger_handlers[trigger].append(handler)
|
||||
def subscribe_predicate(self, trigger, predicate):
|
||||
self.trigger_predicates[trigger].append(predicate)
|
||||
|
||||
def unsubscribe_handler(self, trigger, handler):
|
||||
self.trigger_handlers[trigger].append(handler)
|
||||
def unsubscribe_predicate(self, trigger, predicate):
|
||||
self.trigger_predicates[trigger].append(predicate)
|
||||
|
||||
|
||||
class FSMUpdater:
|
||||
|
Loading…
Reference in New Issue
Block a user