summary refs log tree commit diff
path: root/synapse/util/logcontext.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-05-08 16:52:49 +0100
committerErik Johnston <erik@matrix.org>2015-05-08 16:52:49 +0100
commitda1aa07db5f29436aeaae8d0dcbfe9872b4a7233 (patch)
treeeb508e03e945d04d3a89b73751e605b739d568af /synapse/util/logcontext.py
parentPEP8 (diff)
downloadsynapse-da1aa07db5f29436aeaae8d0dcbfe9872b4a7233.tar.xz
Add some docs
Diffstat (limited to 'synapse/util/logcontext.py')
-rw-r--r--synapse/util/logcontext.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py
index 192e3f49f0..3dce8d2bf3 100644
--- a/synapse/util/logcontext.py
+++ b/synapse/util/logcontext.py
@@ -134,13 +134,25 @@ class PreserveLoggingContext(object):
 
 
 def preserve_context_over_fn(fn, *args, **kwargs):
+    """Takes a function and invokes it with the given arguments, but removes
+    and restores the current logging context while doing so.
+
+    If the result is a deferred, call preserve_context_over_deferred before
+    returning it.
+    """
     with PreserveLoggingContext():
-        deferred = fn(*args, **kwargs)
+        res = fn(*args, **kwargs)
 
-    return preserve_context_over_deferred(deferred)
+    if isinstance(res, defer.Deferred):
+        return preserve_context_over_deferred(res)
+    else:
+        return res
 
 
 def preserve_context_over_deferred(deferred):
+    """Given a deferred wrap it such that any callbacks added later to it will
+    be invoked with the current context.
+    """
     d = defer.Deferred()
 
     current_context = LoggingContext.current_context()