From ec2c17d144c3d6cf117cd0d6aaac0e60b5a0d902 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 12 Jun 2023 15:35:53 -0500 Subject: [PATCH 1/2] `looping_call()` will wait for the given function to finish before scheduling another Thanks to @erikjohnston for clarifying, https://github.com/matrix-org/synapse/pull/15743#discussion_r1226544457 We don't have to worry about calls stacking up if the given function takes longer than the scheduled time. --- synapse/util/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py index 7ea0c4c36bcc..9f3b8741c1db 100644 --- a/synapse/util/__init__.py +++ b/synapse/util/__init__.py @@ -116,6 +116,11 @@ def looping_call( Waits `msec` initially before calling `f` for the first time. + If the function given to `looping_call` returns an awaitable/deferred, the next + call isn't scheduled until after the returned awaitable has finished. We get + this functionality thanks to this function being a thin wrapper around + `twisted.internet.task.LoopingCall`. + Note that the function will be called with no logcontext, so if it is anything other than trivial, you probably want to wrap it in run_as_background_process. From d5c0363b807812cc459c714e04285dd0031dbef5 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 12 Jun 2023 15:41:30 -0500 Subject: [PATCH 2/2] Add changelog --- changelog.d/15772.doc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/15772.doc diff --git a/changelog.d/15772.doc b/changelog.d/15772.doc new file mode 100644 index 000000000000..4d6c933c713b --- /dev/null +++ b/changelog.d/15772.doc @@ -0,0 +1 @@ +Document `looping_call()` functionality that will wait for the given function to finish before scheduling another.