doc: fix release notes typo
[git-cola.git] / cola / notification.py
blob00de47f78e3bd89b36f53f9d27b1e716f9bfb705
1 import os
3 from cola.compat import set
4 from cola.decorators import memoize
7 debug = os.environ.get('COLA_NOTIFIER_DEBUG', False)
10 @memoize
11 def notifier():
12 return Notifier()
15 class Notifier(object):
16 """Object for sending and receiving notification messages"""
18 AMEND = 'amend'
20 def __init__(self):
21 self.channels = {}
23 def broadcast(self, signal, *args, **opts):
24 if debug:
25 print('broadcast: %s(%s, %s)' % (signal,
26 args or '<empty>',
27 opts or '<empty>'))
28 self.emit(signal, *args, **opts)
30 def emit(self, signal, *args, **opts):
31 subscribers = self.channels.get(signal, None)
32 if not subscribers:
33 return
34 for fxn in subscribers:
35 fxn(*args, **opts)
37 def connect(self, signal, callback):
38 subscribers = self.channels.setdefault(signal, set())
39 subscribers.add(callback)