Skip to content

Instantly share code, notes, and snippets.

@i5on9i
Created July 17, 2016 09:30
Show Gist options
  • Save i5on9i/919107d881c0035c06d627aebbdcc49f to your computer and use it in GitHub Desktop.
Save i5on9i/919107d881c0035c06d627aebbdcc49f to your computer and use it in GitHub Desktop.
+-----------+ +-----------+
| | | |
| client | | server |
+-----------+ +-----------+ +-------------------------+
+ + | global_message_buffer |
| |+----------------------------->| |
| POST button is clicked | +-----------+-------------+
| uri: a/message/new | +
| POST, param={'body': 'text444'} | |
+--+ +--+ MessageNewHandler |
| |+----------------------------------->| | create message with id / body |
| | | | |
| | | | |
| | | | |
| | Message id / body / html-form-body | | |
| |<------------------------------------| | |
| | | | new_message([message]) +--+
| | | |--------------------------------------->| |
| | | | | |
| | +-++ | |+---------------------------------+
updater.newMessage | | | | || [loop: self.waiters] |
- show all message | | | | || future.set_result(message ) |
| | | | || |
| | | | || |
| | in chat.js/updater.poll | | |+---------------------------------+
| | uri: a/message/updates | | |
updater.poll | | POST,param={cursor:last_msg_id}/ | | |init-self.waiters()
| | keep pending | | |message --> cache
| |-------------------------------------> | | |trim when the cache is over capacity
| | | +--+
| | | |
| | | wait_for_messages(cursor=cursor) +--+
| | |+--------------------------------------->| |
| | | | | result_future = Future()
| | | | | if message id exist
| | | | | not-delivered-messages <--- cache
| | | | | result_future.set_result(not-delivered-messages)
| | | | |
| | | result_future | | self.waiters.add(result_future)
| | messages =[{'body':'dddd', |<----------------------------------------| |
| | 'id': '342ds',...},...]| +--+
| |<-------------------------------------+| |
| | | yield future |
+--+ | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
v | |
v v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment