Statistics
| Branch: | Revision:

mobicen / varie / util / EventScheduler.py @ 9110387b

History | View | Annotate | Download (635 Bytes)

1
import heapq
2

    
3
class EventScheduler:
4
        def __init__(self):
5
                self.queue = []
6
                self.time = 0
7
                self.last = 0
8

    
9
        def schedule_event(self, interval, e):
10
                t = self.time + interval
11
                if t > self.last:
12
                    self.last = t
13
                heapq.heappush(self.queue, (t, e))
14

    
15
        def pop_event(self):
16
                e = heapq.heappop(self.queue)
17
                self.time = e[0]
18
                return e[1]
19

    
20
        def elapsed_time(self):
21
                return self.time
22

    
23
        def last_event_time(self):
24
                return self.last