self.addr = None
self.ws = None
self.facades = {}
+ self.messages = {}
@property
def is_open(self):
async def close(self):
await self.ws.close()
- async def recv(self):
- result = await self.ws.recv()
- if result is not None:
- result = json.loads(result)
+ async def recv(self, request_id):
+ while not self.messages.get(request_id):
+ await asyncio.sleep(0)
+
+ result = self.messages[request_id]
+
+ del self.messages[request_id]
return result
+ async def receiver(self):
+ while self.is_open:
+ result = await self.ws.recv()
+ if result is not None:
+ result = json.loads(result)
+ self.messages[result['request-id']] = result
+
async def rpc(self, msg, encoder=None):
self.__request_id__ += 1
msg['request-id'] = self.__request_id__
msg['version'] = self.facades[msg['type']]
outgoing = json.dumps(msg, indent=2, cls=encoder)
await self.ws.send(outgoing)
- result = await self.recv()
+ result = await self.recv(msg['request-id'])
if not result:
return result
client = cls(endpoint, uuid, username, password, cacert, macaroons,
loop)
await client.open()
+ self.loop.create_task(self.receiver)
redirect_info = await client.redirect_info()
if not redirect_info: