@@ -263,11 +263,11 @@ def properties(self) -> Dict[Union[str, bytes], Optional[Union[str, bytes]]]:
263263 assert self ._properties is not None
264264 return self ._properties
265265
266- async def async_wait (self , timeout : float ) -> None :
266+ async def async_wait (self , timeout : float , loop : Optional [ asyncio . AbstractEventLoop ] = None ) -> None :
267267 """Calling task waits for a given number of milliseconds or until notified."""
268- loop = get_running_loop ()
269- assert loop is not None
270- await wait_for_future_set_or_timeout ( loop , self . _new_records_futures , timeout )
268+ await wait_for_future_set_or_timeout (
269+ loop or asyncio . get_running_loop (), self . _new_records_futures , timeout
270+ )
271271
272272 def addresses_by_version (self , version : IPVersion ) -> List [bytes ]:
273273 """List addresses matching IP version.
@@ -722,6 +722,9 @@ async def async_request(
722722 if self .load_from_cache (zc , now ):
723723 return True
724724
725+ if TYPE_CHECKING :
726+ assert zc .loop is not None
727+
725728 first_request = True
726729 delay = _LISTENER_TIME
727730 next_ = now
@@ -743,7 +746,7 @@ async def async_request(
743746 delay *= 2
744747 next_ += random .randint (* _AVOID_SYNC_DELAY_RANDOM_INTERVAL )
745748
746- await self .async_wait (min (next_ , last ) - now )
749+ await self .async_wait (min (next_ , last ) - now , zc . loop )
747750 now = current_time_millis ()
748751 finally :
749752 zc .async_remove_listener (self )
0 commit comments