chore: Get rid of all __await__ methods

This commit is contained in:
Gergely Polonkai 2023-11-16 05:40:08 +01:00
parent b30603a190
commit f2a54b5ce6
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
3 changed files with 17 additions and 12 deletions

View File

@ -73,7 +73,10 @@ async def test_client():
print("> RESPONSE:", msg)
try:
print("> RESPONSE:", await api.call("whoami", [], "sync"))
response_handler = api.call("whoami", [], "sync")
response = await response_handler.get_response()
print("> RESPONSE:", response)
except MuxRPCAPIException as e:
print(e)

View File

@ -47,9 +47,13 @@ class MuxRPCRequestHandler(MuxRPCHandler):
def __init__(self, ps_handler):
self.ps_handler = ps_handler
def __await__(self):
msg = yield from self.ps_handler.__await__()
async def get_response(self):
"""Get the response data"""
msg = await self.ps_handler
self.check_message(msg)
return msg

View File

@ -92,9 +92,12 @@ class PSRequestHandler:
if not self.event.is_set():
self.event.set()
def __await__(self):
def __aiter__(self):
return self
async def __anext__(self):
# wait until 'process' is called
yield from self.event.wait().__await__() # pylint: disable=no-member
await self.event.wait()
return self._msg
@ -178,15 +181,10 @@ class PacketStream:
raise StopAsyncIteration()
if msg.req >= 0:
logger.info("RECV: %r", msg)
return msg
async def __await__(self):
async for data in self:
logger.info("RECV: %r", data)
if data is None:
return
async def _read(self):
try:
header = await self.connection.read()