diff options
author | Erik Johnston <erik@matrix.org> | 2021-01-28 19:42:41 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2021-01-28 19:42:41 +0000 |
commit | ccdfa36131546c84bbc96e678f2c25f2a54d752a (patch) | |
tree | 3a40b4161869755466f5b5574524e538223a60ff /synapse | |
parent | Add smoother (diff) | |
download | synapse-ccdfa36131546c84bbc96e678f2c25f2a54d752a.tar.xz |
Fixup
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/util/async_helpers.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/synapse/util/async_helpers.py b/synapse/util/async_helpers.py index 34967bb414..b5843c6443 100644 --- a/synapse/util/async_helpers.py +++ b/synapse/util/async_helpers.py @@ -576,6 +576,8 @@ class Smoother: if not self._queue: return + self._next_call = None + entry = self._queue.popleft() entry.defer.callback(None) @@ -584,7 +586,6 @@ class Smoother: if not self._queue: scheduled_for_ms = (now + self._target_ms + self._last_run) / 2 - print(scheduled_for_ms, now) if scheduled_for_ms <= now: self._last_run = now return @@ -611,25 +612,26 @@ class Smoother: step = self._target_ms / (len(self._queue) + 1) for idx, entry in enumerate(self._queue): new_time = now + (idx + 1) * step - print("Moving?", entry.scheduled_for_ms, new_time) if new_time < entry.scheduled_for_ms: entry.scheduled_for_ms = new_time - if self._next_call: + if self._next_call and not self._next_call.active: self._next_call.reset( max(self._queue[0].scheduled_for_ms - now, 0) / 1000.0 ) else: - self._reactor.callLater( + self._next_call = self._reactor.callLater( max(self._queue[0].scheduled_for_ms - now, 0) / 1000.0, self._fire_next ) await make_deferred_yieldable(entry.defer) + now = self._reactor.seconds() * 1000.0 self._last_run = now - self._reactor.callLater( - (self._queue[0].scheduled_for_ms - now) / 1000.0, self._fire_next, - ) + if self._queue: + self._next_call = self._reactor.callLater( + (self._queue[0].scheduled_for_ms - now) / 1000.0, self._fire_next, + ) return |