@defer.inlineCallbacks
    def wait_for_replication(self, callback, timeout):
        listener = _NotificationListener(None)

        def timed_out():
            listener.deferred.cancel()

        timer = self.clock.call_later(timeout / 1000., timed_out)
        while True:
            listener.deferred = self.replication_deferred.observe()
            result = yield callback()
            if result:
                break

            try:
                with PreserveLoggingContext():
                    yield listener.deferred
            except defer.CancelledError:
                break

        self.clock.cancel_call_later(timer, ignore_errs=True)

        defer.returnValue(result)
Wait for an event to happen.
dataset/ETHPy150Open matrix-org/synapse/synapse/notifier.py/Notifier.wait_for_replication