Reverse future done checks so we know they are actually reachable (#708)

This commit is contained in:
J. Nick Koston 2023-11-25 08:49:54 -06:00 committed by GitHub
parent 3711d54ffa
commit d592f1e7ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 17 deletions

View File

@ -220,8 +220,7 @@ class APIConnection:
if self._debug_enabled:
_LOGGER.debug("Cleaning up connection to %s", self.log_name)
for fut in self._read_exception_futures:
if fut.done():
continue
if not fut.done():
err = self._fatal_exception or APIConnectionError("Connection closed")
new_exc = err
if not isinstance(err, APIConnectionError):
@ -676,8 +675,7 @@ class APIConnection:
def _handle_timeout(self, fut: asyncio.Future[None]) -> None:
"""Handle a timeout."""
if fut.done():
return
if not fut.done():
fut.set_exception(asyncio_TimeoutError)
def _handle_complex_message(
@ -689,8 +687,7 @@ class APIConnection:
resp: message.Message,
) -> None:
"""Handle a message that is part of a response."""
if fut.done():
return
if not fut.done():
if do_append is None or do_append(resp):
responses.append(resp)
if do_stop is None or do_stop(resp):