minor refactor of how we call _next_line()

This commit is contained in:
jesopo 2020-04-29 12:23:11 +01:00
parent 51cfd0f36b
commit 6d4222b4c1

View file

@ -233,21 +233,25 @@ class Server(IServer):
wait_for: Optional[WaitFor] = None wait_for: Optional[WaitFor] = None
wait_for_aw: Optional[Awaitable] = None wait_for_aw: Optional[Awaitable] = None
while True: async def _line() -> Tuple[Line, Optional[Emit]]:
if not waited_reads or wait_for is not None: both = await self._next_line()
both = await self._next_line() waited_reads.append(both)
waited_reads.append(both) line, emit = both
line, emit = both self.line_preread(line)
self.line_preread(line) return both
while True:
if wait_for is not None: if wait_for is not None:
line, emit = waited_reads[-1] line, emit = await _line()
if wait_for.response.match(self, line): if wait_for.response.match(self, line):
wait_for.resolve(line) wait_for.resolve(line)
wait_for, wait_for_aw = await self._line_or_wait( wait_for, wait_for_aw = await self._line_or_wait(
wait_for_aw) wait_for_aw)
else: else:
if not waited_reads:
await _line()
while waited_reads: while waited_reads:
new_line, new_emit = waited_reads.pop(0) new_line, new_emit = waited_reads.pop(0)
line_aw = self._on_read(new_line, new_emit) line_aw = self._on_read(new_line, new_emit)