Skip to content

Instantly share code, notes, and snippets.

@Ivoz
Created February 6, 2012 15:15
Show Gist options
  • Save Ivoz/1752613 to your computer and use it in GitHub Desktop.
Save Ivoz/1752613 to your computer and use it in GitHub Desktop.
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