diff --git a/src/formbridge/bridge/in_process.py b/src/formbridge/bridge/in_process.py index 8cc8c43..93d3cd3 100644 --- a/src/formbridge/bridge/in_process.py +++ b/src/formbridge/bridge/in_process.py @@ -803,7 +803,7 @@ def __init__( def close(self) -> None: """Fence callbacks queued by this bridge instance.""" - self._dispatcher.close() + self._dispatcher.close_dispatch() def register_provider(self, provider: UiCodeDocumentProviderABC) -> None: self._registry.register_code_document_provider(provider) diff --git a/src/formbridge/services/main_thread_dispatch.py b/src/formbridge/services/main_thread_dispatch.py index 15dd03b..a3577b9 100644 --- a/src/formbridge/services/main_thread_dispatch.py +++ b/src/formbridge/services/main_thread_dispatch.py @@ -88,9 +88,16 @@ def _complete(self) -> None: class MainThreadDispatcher(ABC): - """Own every callable queued onto the owner thread.""" + """Own every callable queued onto the owner thread. - def __init__(self) -> None: + A capability as well as an object: a toolkit's application widget can inherit its + member beside the widget base (the constructor continues the cooperative chain), so + posting work onto its thread is the application's own method, not a forward to a + helper. Its shutdown is ``close_dispatch``, named apart from the widget's ``close``. + """ + + def __init__(self, *args: object, **kwargs: object) -> None: + super().__init__(*args, **kwargs) self._lock = threading.Lock() self._closed = False self._calls: set[DispatchedCall] = set() @@ -110,7 +117,7 @@ def _deliver(self, call: DispatchedCall) -> None: def _undeliverable_error(self) -> MainThreadDispatchError: return MainThreadDispatchError("No owner thread is available for dispatch.") - def close(self) -> None: + def close_dispatch(self) -> None: """Reject new work and cancel callbacks which have not begun.""" with self._lock: diff --git a/tests/test_main_thread_dispatch.py b/tests/test_main_thread_dispatch.py index ef7a9e6..122a129 100644 --- a/tests/test_main_thread_dispatch.py +++ b/tests/test_main_thread_dispatch.py @@ -70,7 +70,7 @@ def test_close_cancels_posted_work_and_rejects_new_work() -> None: dispatcher = QueuedMainThreadDispatcher() calls: list[str] = [] dispatcher.post(lambda: calls.append("late")) - dispatcher.close() + dispatcher.close_dispatch() finished: Future[None] = Future() finished.set_result(None) dispatcher.run_until(finished)