Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add ability to pass arguments to looping calls #5780

Merged
merged 3 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5780.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow looping calls to be given arguments.
6 changes: 4 additions & 2 deletions synapse/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def time_msec(self):
"""Returns the current system time in miliseconds since epoch."""
return int(self.time() * 1000)

def looping_call(self, f, msec):
def looping_call(self, f, msec, *args, **kwargs):
"""Call a function repeatedly.

Waits `msec` initially before calling `f` for the first time.
Expand All @@ -70,8 +70,10 @@ def looping_call(self, f, msec):
Args:
f(function): The function to call repeatedly.
msec(float): How long to wait between calls in milliseconds.
*args: Postional arguments to pass to function.
**kwargs: Key arguments to pass to function.
"""
call = task.LoopingCall(f)
call = task.LoopingCall(f, *args, **kwargs)
call.clock = self._reactor
d = call.start(msec / 1000.0, now=False)
d.addErrback(log_failure, "Looping call died", consumeErrors=False)
Expand Down