Mercurial > cosocket
view channels.py @ 50:f78b986ecb6e
OWC now remembers your name.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Tue, 28 Apr 2009 19:08:16 +0000 |
parents | 425776983cf2 |
children | b0f802c4fafc |
line wrap: on
line source
import cosocket _channels = {} class until_message_sent(object): def __init__(self, channel_name, message): self.channel_name = channel_name self.message = message def execute(self, dispatcher): if self.channel_name in _channels: receivers = _channels[self.channel_name].values() del _channels[self.channel_name] for receiver in receivers: receiver.continue_from_yield(self.message) dispatcher.continue_from_yield() class _until_message_received(object): def __init__(self, channel_name): self.channel_name = channel_name self._fd = None def execute(self, dispatcher): if self.channel_name not in _channels: _channels[self.channel_name] = {} self._fd = dispatcher.socket.fileno() _channels[self.channel_name][self._fd] = dispatcher def abort(self): if (self.channel_name in _channels and self._fd in _channels[self.channel_name]): del _channels[self.channel_name][self._fd] def until_message_received(channel_name): instruction = _until_message_received(channel_name) try: message = yield instruction yield cosocket.return_value(message) except GeneratorExit: instruction.abort() raise