Small speed up to async_listen (#103307)

Avoid constructing an inner function each time we call async_listen
and use a partial which holds a reference to the function body with new
args instead of making another full function
This commit is contained in:
J. Nick Koston 2023-11-03 14:58:03 -05:00 committed by GitHub
parent 062b510ec0
commit dca72c598e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1176,12 +1176,9 @@ class EventBus:
self, event_type: str, filterable_job: _FilterableJobType
) -> CALLBACK_TYPE:
self._listeners.setdefault(event_type, []).append(filterable_job)
def remove_listener() -> None:
"""Remove the listener."""
self._async_remove_listener(event_type, filterable_job)
return remove_listener
return functools.partial(
self._async_remove_listener, event_type, filterable_job
)
def listen_once(
self,