fix: Make MuxRPCAPI.__await__ a sync method

This commit is contained in:
Gergely Polonkai 2023-11-02 09:48:37 +01:00
parent 740762b149
commit 9ca68307f0
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4

View File

@ -134,16 +134,23 @@ class MuxRPCAPI:
self.handlers = {}
self.connection = None
async def __await__(self):
async for req_message in self.connection:
def __aiter__(self):
return self
async def __anext__(self):
req_message = await self.connection.__anext__()
if req_message is None:
return
raise StopAsyncIteration()
body = req_message.body
if isinstance(body, dict) and body.get("name"):
self.process(self.connection, MuxRPCRequest.from_message(req_message))
def __await__(self):
yield from self.__anext__().__await__()
def add_connection(self, connection):
"""Set the packet stream connection of this RPC API"""