Skip to content

Instantly share code, notes, and snippets.

@tioover
Created May 5, 2012 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tioover/2603165 to your computer and use it in GitHub Desktop.
Save tioover/2603165 to your computer and use it in GitHub Desktop.
tornado chat Learning
#将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