Mercurial > piecrust2
comparison piecrust/events.py @ 3:f485ba500df3
Gigantic change to basically make PieCrust 2 vaguely functional.
- Serving works, with debug window.
- Baking works, multi-threading, with dependency handling.
- Various things not implemented yet.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 10 Aug 2014 23:43:16 -0700 |
parents | |
children | f070a4fc033c |
comparison
equal
deleted
inserted
replaced
2:40fa08b261b9 | 3:f485ba500df3 |
---|---|
1 | |
2 class Event(object): | |
3 def __init__(self): | |
4 self._handlers = [] | |
5 | |
6 def __iadd__(self, handler): | |
7 self._handlers.append(handler) | |
8 return self | |
9 | |
10 def __isub__(self, handler): | |
11 self._handlers.remove(handler) | |
12 return self | |
13 | |
14 def fire(self, *args, **kwargs): | |
15 # Make a copy of the handlers list in case some handler removes | |
16 # itself while executing. | |
17 handlers = list(self._handlers) | |
18 for handler in handlers: | |
19 handler(*args, **kwargs) | |
20 |