summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2019-09-25 18:17:39 +0100
committerRichard van der Hoff <richard@matrix.org>2019-09-25 18:17:39 +0100
commita96318127dc17ee102bcf90821d90b7e6079a85d (patch)
tree71dd953794ce378ef0e911665e0c8f5f8b22b57e
parentMerge branch 'develop' of github.com:matrix-org/synapse into erikj/cleanup_us... (diff)
downloadsynapse-a96318127dc17ee102bcf90821d90b7e6079a85d.tar.xz
Update comments and docstring
-rw-r--r--synapse/metrics/background_process_metrics.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/synapse/metrics/background_process_metrics.py b/synapse/metrics/background_process_metrics.py
index b24e2fab4a..c53d2a0d40 100644
--- a/synapse/metrics/background_process_metrics.py
+++ b/synapse/metrics/background_process_metrics.py
@@ -175,7 +175,7 @@ def run_as_background_process(desc, func, *args, **kwargs):
 
     Args:
         desc (str): a description for this background process type
-        func: a function, which may return a Deferred
+        func: a function, which may return a Deferred or a coroutine
         args: positional args for func
         kwargs: keyword args for func
 
@@ -199,11 +199,13 @@ def run_as_background_process(desc, func, *args, **kwargs):
                 _background_processes.setdefault(desc, set()).add(proc)
 
             try:
-                # We ensureDeferred here to handle coroutines
                 result = func(*args, **kwargs)
 
-                # We need this check because ensureDeferred doesn't like when
-                # func doesn't return a Deferred or coroutine.
+                # We probably don't have an ensureDeferred in our call stack to handle
+                # coroutine results, so we need to ensureDeferred here.
+                #
+                # But we need this check because ensureDeferred doesn't like being
+                # called on immediate values (as opposed to Deferreds or coroutines).
                 if iscoroutine(result):
                     result = defer.ensureDeferred(result)