Coroutine-based signal implementation. To connect a callback to a signal, use any list method. Signals are fired using the :meth:`send` coroutine, which takes named arguments.
| 19 | |
| 20 | |
| 21 | class Signal(BaseSignal): |
| 22 | """Coroutine-based signal implementation. |
| 23 | |
| 24 | To connect a callback to a signal, use any list method. |
| 25 | |
| 26 | Signals are fired using the :meth:`send` coroutine, which takes named |
| 27 | arguments. |
| 28 | """ |
| 29 | |
| 30 | def __init__(self, app): |
| 31 | super().__init__() |
| 32 | self._app = app |
| 33 | klass = self.__class__ |
| 34 | self._name = klass.__module__ + ':' + klass.__qualname__ |
| 35 | self._pre = app.on_pre_signal |
| 36 | self._post = app.on_post_signal |
| 37 | |
| 38 | @asyncio.coroutine |
| 39 | def send(self, *args, **kwargs): |
| 40 | """ |
| 41 | Sends data to all registered receivers. |
| 42 | """ |
| 43 | ordinal = None |
| 44 | debug = self._app._debug |
| 45 | if debug: |
| 46 | ordinal = self._pre.ordinal() |
| 47 | yield from self._pre.send(ordinal, self._name, *args, **kwargs) |
| 48 | yield from self._send(*args, **kwargs) |
| 49 | if debug: |
| 50 | yield from self._post.send(ordinal, self._name, *args, **kwargs) |
| 51 | |
| 52 | |
| 53 | class DebugSignal(BaseSignal): |
no outgoing calls