refactor: Change MuxRPC.__await__ MuxRPC.process_messages
`__await__` can be a bit dangerous in the world of `asyncio`.
This commit is contained in:
parent
3b2c5cc792
commit
69433cab86
@ -105,7 +105,7 @@ async def main(keypair):
|
|||||||
packet_stream = PacketStream(client)
|
packet_stream = PacketStream(client)
|
||||||
await client.open()
|
await client.open()
|
||||||
api.add_connection(packet_stream)
|
api.add_connection(packet_stream)
|
||||||
await gather(ensure_future(api), test_client())
|
await gather(ensure_future(api.process_messages()), test_client())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -155,11 +155,15 @@ class MuxRPCAPI:
|
|||||||
self.handlers = {}
|
self.handlers = {}
|
||||||
self.connection = None
|
self.connection = None
|
||||||
|
|
||||||
async def __await__(self):
|
async def process_messages(self):
|
||||||
|
"""Continuously process incoming messages"""
|
||||||
|
|
||||||
async for req_message in self.connection:
|
async for req_message in self.connection:
|
||||||
body = req_message.body
|
body = req_message.body
|
||||||
|
|
||||||
if req_message is None:
|
if req_message is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if isinstance(body, dict) and body.get("name"):
|
if isinstance(body, dict) and body.get("name"):
|
||||||
self.process(self.connection, MuxRPCRequest.from_message(req_message))
|
self.process(self.connection, MuxRPCRequest.from_message(req_message))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user