Skip to content

Commit

Permalink
Update client.py
Browse files Browse the repository at this point in the history
  • Loading branch information
wwww-wwww committed Apr 8, 2021
1 parent debb72f commit ae5b10b
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions phxsocket/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ async def _broadcast(self, websocket, send_queue):
await websocket.send(message)
send_queue.task_done()
except:
pass
logging.error("phxsocket: FATAL ERROR: " + traceback.format_exc())

async def _run(self, loop, send_queue, connect_evt, shutdown_evt):
async with websockets.connect(self.url) as websocket:
connect_evt.respond(None)
loop.create_task(self._broadcast(websocket, send_queue))
broadcast = loop.create_task(self._broadcast(websocket, send_queue))
listen = loop.create_task(self._listen(websocket))
shutdown = loop.create_task(shutdown_evt.wait())
await asyncio.wait({listen, shutdown},
await asyncio.wait({listen, shutdown, broadcast},
return_when=asyncio.FIRST_COMPLETED,
loop=loop)

Expand All @@ -119,8 +119,6 @@ def run(self, connect_evt):
self._send_queue = asyncio.Queue()
self._shutdown_evt = asyncio.Event()

tasks_pending = []

try:
loop.run_until_complete(
self._run(loop, self._send_queue, connect_evt, self._shutdown_evt))
Expand All @@ -140,12 +138,8 @@ def run(self, connect_evt):
loop.close()
self._loop = None

Thread(target=self._on_close, args=[connect_evt], daemon=True).start()

def _on_close(self, connect_evt):
self.thread.join()
if connect_evt.is_set() and self.on_close:
self.on_close(self)
if connect_evt.is_set() and self.on_close:
self.on_close(self)

def close(self):
if not self._loop:
Expand Down

0 comments on commit ae5b10b

Please sign in to comment.