Package pyjamas :: Module DeferredCommand
[hide private]
[frames] | no frames]

Source Code for Module pyjamas.DeferredCommand

 1  from pyjamas.Timer import Timer 
 2   
 3  deferredCommands = [] 
 4  timerIsActive = False 
 5   
 6   
7 -def add(cmd):
8 deferredCommands.append(cmd) 9 maybeSetDeferredCommandTimer()
10 11
12 -def flushDeferredCommands():
13 for i in range(len(deferredCommands)): 14 current = deferredCommands[0] 15 del deferredCommands[0] 16 if current: 17 if hasattr(current, "execute"): 18 current.execute() 19 else: 20 current()
21 22
23 -def maybeSetDeferredCommandTimer():
24 global timerIsActive 25 26 if (not timerIsActive) and (not len(deferredCommands) == 0): 27 Timer(1, onTimer) 28 timerIsActive = True
29 30
31 -def onTimer(t):
32 global timerIsActive 33 34 flushDeferredCommands() 35 timerIsActive = False 36 maybeSetDeferredCommandTimer()
37