Created
March 21, 2012 14:19
-
-
Save dayvson/2147261 to your computer and use it in GitHub Desktop.
EventBus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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