Refine Mplex.close and SwarmConn.close

Ensure `close` cleans up things and cancel the service finally.
This commit is contained in:
mhchia
2019-12-17 15:50:55 +08:00
parent d847e78a83
commit fb0519129d
13 changed files with 71 additions and 51 deletions

View File

@ -91,7 +91,9 @@ class Mplex(IMuxedConn, Service):
await self.secured_conn.close()
# Blocked until `close` is finally set.
await self.event_closed.wait()
await self.manager.stop()
@property
def is_closed(self) -> bool:
"""
check connection is fully closed.
@ -213,10 +215,6 @@ class Mplex(IMuxedConn, Service):
return channel_id, flag, message
@property
def _id(self) -> int:
return 0 if self.is_initiator else 1
async def _handle_incoming_message(self) -> None:
"""
Read and handle a new incoming message.