diff options
author | Erik Johnston <erik@matrix.org> | 2017-03-31 13:36:38 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2017-03-31 15:42:51 +0100 |
commit | 1df7c28661207df8575fd519ce9c23690b9156ec (patch) | |
tree | 552fe2ad1e12d81baec550c1dc47c2eeed71639e /synapse/notifier.py | |
parent | Add a timestamp to USER_SYNC command (diff) | |
download | synapse-1df7c28661207df8575fd519ce9c23690b9156ec.tar.xz |
Use callbacks to notify tcp replication rather than deferreds
Diffstat (limited to 'synapse/notifier.py')
-rw-r--r-- | synapse/notifier.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/synapse/notifier.py b/synapse/notifier.py index f9fcc0ca25..4fda184b7a 100644 --- a/synapse/notifier.py +++ b/synapse/notifier.py @@ -163,6 +163,8 @@ class Notifier(object): self.store = hs.get_datastore() self.pending_new_room_events = [] + self.replication_callbacks = [] + self.clock = hs.get_clock() self.appservice_handler = hs.get_application_service_handler() @@ -202,6 +204,12 @@ class Notifier(object): lambda: len(self.user_to_user_stream), ) + def add_replication_callback(self, cb): + """Add a callback that will be called when some new data is available. + Callback is not given any arguments. + """ + self.replication_callbacks.append(cb) + @preserve_fn def on_new_room_event(self, event, room_stream_id, max_room_stream_id, extra_users=[]): @@ -510,6 +518,9 @@ class Notifier(object): self.replication_deferred = ObservableDeferred(defer.Deferred()) deferred.callback(None) + for cb in self.replication_callbacks: + preserve_fn(cb)() + @defer.inlineCallbacks def wait_for_replication(self, callback, timeout): """Wait for an event to happen. @@ -550,9 +561,3 @@ class Notifier(object): break defer.returnValue(result) - - def wait_once_for_replication(self): - """Returns a deferred which resolves when there is new data for - replication to handle. - """ - return self.replication_deferred.observe() |