small fix to websocketchannel and relay

This commit is contained in:
Timothy Pogue 2022-11-17 12:03:11 -07:00
parent 875e9ab447
commit ce43fa5f43
1 changed files with 17 additions and 14 deletions

View File

@ -77,6 +77,7 @@ class WebSocketChannel:
# until self.drain_timeout for the relay to drain the outgoing queue # until self.drain_timeout for the relay to drain the outgoing queue
# We can't use asyncio.wait_for here because the queue may have been created with a # We can't use asyncio.wait_for here because the queue may have been created with a
# different eventloop # different eventloop
if not self.is_closed():
start = time.time() start = time.time()
while self.queue.full(): while self.queue.full():
await asyncio.sleep(1) await asyncio.sleep(1)
@ -91,6 +92,8 @@ class WebSocketChannel:
# If we got here everything is ok # If we got here everything is ok
return True return True
else:
return False
async def recv(self): async def recv(self):
""" """
@ -109,14 +112,14 @@ class WebSocketChannel:
Close the WebSocketChannel Close the WebSocketChannel
""" """
self._closed.set()
self._relay_task.cancel()
try: try:
await self.raw_websocket.close() await self.raw_websocket.close()
except Exception: except Exception:
pass pass
self._closed.set()
self._relay_task.cancel()
def is_closed(self) -> bool: def is_closed(self) -> bool:
""" """
Closed flag Closed flag