Only run 'startup sequence' on reconnect

When a client loses a connection it will currently need to re-subscribe
for symbols and receive a symbol data summary as a first quote response.
Only run the provided coroutine on reconnect and call the kwarg
`on_reconnect`. The client consuming code is entirely expected at this
point to know how the symbol registration protocol works.
kivy_mainline_and_py3.8
Tyler Goodlet 2018-05-16 19:15:43 -04:00
parent 09ae9f5ef1
commit 186befc704
1 changed files with 4 additions and 3 deletions

View File

@ -116,11 +116,11 @@ class Client:
"""
def __init__(
self, sockaddr: tuple,
startup_seq: Coroutine,
on_reconnect: Coroutine,
auto_reconnect: bool = True,
):
self.sockaddr = sockaddr
self._startup_seq = startup_seq
self._recon_seq = on_reconnect
self._autorecon = auto_reconnect
self.squeue = None
@ -128,7 +128,6 @@ class Client:
sockaddr = sockaddr or self.sockaddr
stream = await trio.open_tcp_stream(*sockaddr, **kwargs)
self.squeue = StreamQueue(stream)
await self._startup_seq(self)
return stream
async def send(self, item):
@ -168,6 +167,8 @@ class Client:
continue
else:
log.warn("Stream connection re-established!")
# run any reconnection sequence
await self._recon_seq(self)
break
except (OSError, ConnectionRefusedError):
if not down: