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 -def add(cmd):
7 deferredCommands.append(cmd) 8 maybeSetDeferredCommandTimer()
9
10 -def flushDeferredCommands():
11 for i in range(len(deferredCommands)): 12 current = deferredCommands[0] 13 del deferredCommands[0] 14 if current: 15 current.execute()
16
17 -def maybeSetDeferredCommandTimer():
18 global timerIsActive 19 20 if (not timerIsActive) and (not len(deferredCommands)==0): 21 Timer(1, onTimer) 22 timerIsActive = True
23
24 -def onTimer(t):
25 global timerIsActive 26 27 flushDeferredCommands() 28 timerIsActive = False 29 maybeSetDeferredCommandTimer()
30