Created
February 6, 2012 15:15
-
-
Save Ivoz/1752613 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import gevent | |
class Publisher(object): | |
def __init__(self): | |
self.channels = [] | |
self.subscribers = [] | |
self.subscriptions = {} | |
self.publications = {} | |
def distribute(self, channel): | |
def publication(): | |
for article in channel: | |
for sub in self.subscriptions[hash(channel)]: | |
sub.put(article) | |
self.publications[hash(channel)] = gevent.spawn(publication) | |
def subscribe(self, subscriber, channel): | |
if hash(channel) not in self.subscriptions: | |
self.subscriptions[hash(channel)] = [] | |
self.subscriptions[hash(channel)].append(subscriber) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment