|
- import time
-
- class desktop_SequentialTimer():
- def __init__(self):
- self.activeTimeout = None
- self.callback = None
- self.queue = []
- #}
-
- def update(self):
- # Get current time in milliseconds.
- now = time.time_ns() // 1000000
-
- # Schedule an item.
- if (
- self.activeTimeout == None and
- len(self.queue) > 0
- ):
- self.activeTimeout = now + self.queue[0][0]
- elif (
- self.activeTimeout != None and
- now >= self.activeTimeout
- ):
- # Report when the time is up.
- key = self.queue[0][1]
- value = self.queue[0][2]
- self.queue.pop(0)
- self.activeTimeout = None
- self.callback(key, value)
- #}
- #}
-
- def schedule(self, key, value, timeout):
- self.queue.append([timeout, key, value])
- #}
|