Better reconnect logic

This commit is contained in:
Tony Garnock-Jones 2018-11-21 14:24:09 +00:00
parent d3be010ffd
commit 8eb1d320ae
1 changed files with 6 additions and 6 deletions

12
chat.py
View File

@ -37,12 +37,12 @@ S.Endpoint(conn, S.Observe(Says(S.CAPTURE, S.CAPTURE)),
on_msg=lambda who, what: print(who, 'said', repr(what))) on_msg=lambda who, what: print(who, 'said', repr(what)))
async def reconnect(loop): async def reconnect(loop):
while True: while conn:
await conn.main(loop, on_connected=lambda: print('-'*50, 'Connected')) did_connect = await conn.main(loop, on_connected=lambda: print('-'*50, 'Connected'))
if not conn: break if did_connect:
print('-'*50, 'Disconnected') print('-'*50, 'Disconnected')
await asyncio.sleep(2) else:
if not conn: break await asyncio.sleep(2)
def accept_input(loop): def accept_input(loop):
global conn global conn