laneya

multiplayer roguelike game
git clone https://git.ce9e.org/laneya.git

commit
443849e4a5c4e5903efbf8d452f633ea0281e829
parent
aad2aa7237e4d310c25f7bf8581ad0202e05e2b3
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2014-10-04 16:02
timeout response promises

Diffstat

M laneya/protocol.py 10 +++++++++-

1 files changed, 9 insertions, 1 deletions


diff --git a/laneya/protocol.py b/laneya/protocol.py

@@ -66,6 +66,7 @@ import json
   66    66 
   67    67 from twisted.python import log
   68    68 from twisted.protocols.basic import NetstringReceiver
   -1    69 from twisted.internet import reactor
   69    70 
   70    71 import deferred as q
   71    72 import actions
@@ -176,6 +177,13 @@ class Protocol(JSONProtocol):
  176   177         else:
  177   178             log.err('Message type not known: %s' % message['type'])
  178   179 
   -1   180     def _timeout(self, d, key):
   -1   181         try:
   -1   182             d.reject('timeout', silent=True)
   -1   183             del self._responseDeferreds[key]
   -1   184         except KeyError:
   -1   185             pass
   -1   186 
  179   187     def sendRequest(self, user, action, **kwargs):
  180   188         """Send a request and get a promise yielding the response."""
  181   189         data = {
@@ -187,9 +195,9 @@ class Protocol(JSONProtocol):
  187   195         }
  188   196         self.sendJSON(data)
  189   197 
  190    -1         # TODO: d should be rejected after a timeout
  191   198         d = q.Deferred()
  192   199         self._responseDeferreds[data['key']] = d
   -1   200         reactor.callLater(10, self._timeout(d, data['key']))
  193   201         return d.promise
  194   202 
  195   203     def _sendResponse(self, key, status, **kwargs):