/library/DeferredCommand.py
Python | 39 lines | 27 code | 12 blank | 0 comment | 5 complexity | 2acd2ff87acdf26c94d971496fb88d67 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
- from Timer import Timer
- deferredCommands = []
- timerIsActive = False
- class DeferredCommand:
- def add(self, cmd):
- global deferredCommands
- deferredCommands.append(cmd)
- self.maybeSetDeferredCommandTimer()
-
- def flushDeferredCommands(self):
- global deferredCommands
-
- for i in range(len(deferredCommands)):
- current = deferredCommands[0]
- del deferredCommands[0]
-
- if current == None:
- return
- else:
- current.execute()
- def maybeSetDeferredCommandTimer(self):
- global timerIsActive, deferredCommands
-
- if (not timerIsActive) and (not len(deferredCommands)==0):
- Timer(1, self)
- timerIsActive = True
-
- def onTimer(self):
- global timerIsActive
- self.flushDeferredCommands()
- timerIsActive = False
- self.maybeSetDeferredCommandTimer()