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 #5781 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
michaelkaye authored Aug 8, 2019
2 parents 8551b4f + 132887d commit 63d0d21
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 @@ -58,16 +58,18 @@ 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.
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(
Expand Down

0 comments on commit 63d0d21

Please sign in to comment.