Created
May 5, 2012 15:11
-
-
Save tioover/2603165 to your computer and use it in GitHub Desktop.
tornado chat Learning
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
#将callback添加到一个类里面 | |
class MessageMixin(object): | |
waiters = set() | |
MessageMixin.waiters.add(callback) | |
#在有新的消息的时候遍历waiters返回 | |
for callback in waiters: | |
callbask(message) | |
def callback(self, messages): | |
#callback也就是关闭连接然后返回传过来的消息 | |
# Closed client connection | |
if self.request.connection.stream.closed(): | |
return | |
self.finish(dict(messages=messages)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment