Created
July 17, 2016 09:30
-
-
Save i5on9i/919107d881c0035c06d627aebbdcc49f to your computer and use it in GitHub Desktop.
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
+-----------+ +-----------+ | |
| | | | | |
| 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