Skip to content

Instantly share code, notes, and snippets.

@dayvson
Created March 21, 2012 14:19
Show Gist options
  • Save dayvson/2147261 to your computer and use it in GitHub Desktop.
Save dayvson/2147261 to your computer and use it in GitHub Desktop.
EventBus
class EventBus(object):
def __init__(self):
self.subscriptions = {}
def subscribe(self, subject, func):
if not subject in self.subscriptions:
self.subscriptions[subject] = []
self.subscriptions[subject].append(func)
def publish(self, subject, data, *args, **kw):
if subject not in self.subscriptions:
return
for subscription in self.subscriptions[subject]:
subscription(data, *args, **kw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment