Skip to content

Commit 0c88ecf

Browse files
authored
feat: improve AsyncServiceBrowser performance (#1273)
1 parent 2734db9 commit 0c88ecf

3 files changed

Lines changed: 9 additions & 14 deletions

File tree

src/zeroconf/_services/browser.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ cdef class _ServiceBrowserBase(RecordUpdateListener):
7474
cpdef _async_send_ready_queries(self, object now)
7575

7676
cpdef _cancel_send_timer(self)
77+
78+
cpdef async_update_records_complete(self)

src/zeroconf/_services/browser.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import random
2626
import threading
2727
import warnings
28-
from abc import abstractmethod
2928
from types import TracebackType # noqa # used in type hints
3029
from typing import (
3130
TYPE_CHECKING,
@@ -437,14 +436,18 @@ def async_update_records(self, zc: 'Zeroconf', now: float_, records: List[Record
437436
for type_, name in self._names_matching_types((record.name,)):
438437
self._enqueue_callback(SERVICE_STATE_CHANGE_UPDATED, type_, name)
439438

440-
@abstractmethod
441439
def async_update_records_complete(self) -> None:
442440
"""Called when a record update has completed for all handlers.
443441
444442
At this point the cache will have the new records.
445443
446444
This method will be run in the event loop.
445+
446+
This method is expected to be overridden by subclasses.
447447
"""
448+
for pending in self._pending_handlers.items():
449+
self._fire_service_state_changed_event(pending)
450+
self._pending_handlers.clear()
448451

449452
def _fire_service_state_changed_event(self, event: Tuple[Tuple[str, str], ServiceStateChange]) -> None:
450453
"""Fire a service state changed event.
@@ -454,7 +457,8 @@ def _fire_service_state_changed_event(self, event: Tuple[Tuple[str, str], Servic
454457
455458
When running with AsyncServiceBrowser, this will happen in the event loop.
456459
"""
457-
name_type, state_change = event
460+
name_type = event[0]
461+
state_change = event[1]
458462
self._service_state_changed.fire(
459463
zeroconf=self.zc,
460464
service_type=name_type[1],

src/zeroconf/asyncio.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,6 @@ async def async_cancel(self) -> None:
8282
"""Cancel the browser."""
8383
self._async_cancel()
8484

85-
def async_update_records_complete(self) -> None:
86-
"""Called when a record update has completed for all handlers.
87-
88-
At this point the cache will have the new records.
89-
90-
This method will be run in the event loop.
91-
"""
92-
for pending in self._pending_handlers.items():
93-
self._fire_service_state_changed_event(pending)
94-
self._pending_handlers.clear()
95-
9685
async def __aenter__(self) -> 'AsyncServiceBrowser':
9786
return self
9887

0 commit comments

Comments
 (0)