@@ -527,18 +527,24 @@ def async_add(self, now: float, answers: _AnswerWithAdditionalsType) -> None:
527527 last_group .answers .update (answers )
528528 return
529529 else :
530- self .zc .loop .call_later (millis_to_seconds (random_delay ), self ._async_ready )
530+ self .zc .loop .call_later (millis_to_seconds (random_delay ), self .async_ready )
531531 self .queue .append (AnswerGroup (send_after , send_before , answers ))
532532
533- def _async_ready (self ) -> None :
533+ def _remove_answers_from_queue (self , answers : _AnswerWithAdditionalsType ) -> None :
534+ """Remove a set of answers from the outgoing queue."""
535+ for pending in self .queue :
536+ for record in answers :
537+ pending .answers .pop (record , None )
538+
539+ def async_ready (self ) -> None :
534540 """Process anything in the queue that is ready."""
535541 assert self .zc .loop is not None
536542 now = current_time_millis ()
537543
538544 if len (self .queue ) > 1 and self .queue [0 ].send_before > now :
539545 # There is more than one answer in the queue,
540546 # delay until we have to send it (first answer group reaches send_before)
541- self .zc .loop .call_later (millis_to_seconds (self .queue [0 ].send_before - now ), self ._async_ready )
547+ self .zc .loop .call_later (millis_to_seconds (self .queue [0 ].send_before - now ), self .async_ready )
542548 return
543549
544550 answers : _AnswerWithAdditionalsType = {}
@@ -549,12 +555,9 @@ def _async_ready(self) -> None:
549555 if len (self .queue ):
550556 # If there are still groups in the queue that are not ready to send
551557 # be sure we schedule them to go out later
552- self .zc .loop .call_later (millis_to_seconds (self .queue [0 ].send_after - now ), self ._async_ready )
558+ self .zc .loop .call_later (millis_to_seconds (self .queue [0 ].send_after - now ), self .async_ready )
553559
554560 if answers :
555- # If we have the same answer scheduled to go out, remove it
556- for pending in self .queue :
557- for record in answers :
558- pending .answers .pop (record , None )
559-
561+ # If we have the same answer scheduled to go out, remove them
562+ self ._remove_answers_from_queue (answers )
560563 self .zc .async_send (construct_outgoing_multicast_answers (answers ))
0 commit comments