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

Commit

Permalink
Merge pull request #5780 from matrix-org/baboliver/loopingcall-args
Browse files Browse the repository at this point in the history
Add ability to pass arguments to looping calls
  • Loading branch information
babolivier authored Jul 29, 2019
2 parents d74595e + bd083a5 commit fa87004
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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

0 comments on commit fa87004

Please sign in to comment.