Also add the library id when dispatching events

This commit is contained in:
Kovid Goyal 2021-08-10 12:09:14 +05:30
parent 559d467556
commit d3681ca528
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 5 additions and 4 deletions

View File

@ -427,10 +427,10 @@ class Cache(object):
def add_listener(self, event_callback_function):
'''
Register a callback function that will be called after certain actions are
taken on this database. The function must take two arguments, the first of
which is the event type (:class:`EventType`) and the second is a tuple
containing event type specific data.
taken on this database. The function must take three arguments:
(:class:`EventType`, library_id, event_type_specific_data)
'''
self.event_dispatcher.library_id = getattr(self, 'server_library_id', self.library_id)
self.event_dispatcher.add_listener(event_callback_function)
@write_api

View File

@ -46,6 +46,7 @@ class EventDispatcher:
self.refs = []
self.queue = Queue()
self.activated = False
self.library_id = ''
def add_listener(self, callback):
# note that we intentionally leak dead weakrefs. To not do so would
@ -66,7 +67,7 @@ class EventDispatcher:
def __call__(self, event_name, *args):
if self.activated:
self.queue.put((event_name, args))
self.queue.put((event_name, self.library_id, args))
def close(self):
if self.activated: