diff --git a/src/zeroconf/_services/info.py b/src/zeroconf/_services/info.py index cc1db05f2..b75d6277e 100644 --- a/src/zeroconf/_services/info.py +++ b/src/zeroconf/_services/info.py @@ -89,6 +89,12 @@ def instance_name_from_service_info(info: "ServiceInfo") -> str: _cached_ip_addresses = lru_cache(maxsize=256)(ip_address) +def _set_future_none_if_not_done(fut: asyncio.Future) -> None: + """Set a future to None if it is not done.""" + if not fut.done(): # pragma: no branch + fut.set_result(None) + + class ServiceInfo(RecordUpdateListener): """Service information. @@ -235,7 +241,7 @@ async def async_wait(self, timeout: float) -> None: loop = asyncio.get_running_loop() future = loop.create_future() self._new_records_futures.append(future) - handle = loop.call_later(millis_to_seconds(timeout), future.set_result, None) + handle = loop.call_later(millis_to_seconds(timeout), _set_future_none_if_not_done, future) try: await future finally: