Skip to content
Browse files

Requests learned "hasresponse" to check asyncronously whether the res…

…ponse has arrived or not. Also added a __call__ method to get the value.
  • Loading branch information...
1 parent 9495e31 commit 7e5197bdd18998511476cf86010c12681cabeaea @deavid committed Apr 30, 2011
Showing with 12 additions and 0 deletions.
  1. +12 −0 bjsonrpc/request.py
View
12 bjsonrpc/request.py
@@ -70,6 +70,15 @@ def __init__(self, conn, request_data):
data = json.dumps(self.data, self.conn)
self.conn.write(data)
+
+ def hasresponse(self):
+ """
+ Method thet checks if there's a response or not.
+ Returns True if there it is or False if it haven't arrived yet.
+ """
+ if self.response is not None: return True
+ self.conn.dispatch_until_empty()
+ return self.response is not None
def setresponse(self, value):
"""
@@ -101,6 +110,9 @@ def wait(self):
while self.response is None:
self.conn.read_and_dispatch(condition=lambda: self.response is None)
+
+ def __call__(self):
+ return self.value
@property
def value(self):

0 comments on commit 7e5197b

Please sign in to comment.
Something went wrong with that request. Please try again.