summary refs log tree commit diff
path: root/synapse/util/async_helpers.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-10-30 11:35:46 +0000
committerErik Johnston <erik@matrix.org>2019-10-30 11:35:46 +0000
commit326b3dace77aeb36e516ea9b04ba1baa171bcb47 (patch)
tree5eb76e0cd616ac49bbaf0eede5705411fd31401c /synapse/util/async_helpers.py
parentFix typo in domain name in account_threepid_delegates config option (#6273) (diff)
downloadsynapse-326b3dace77aeb36e516ea9b04ba1baa171bcb47.tar.xz
Make ObservableDeferred.observe() always return deferred.
This makes it easier to use in an async/await world.

Also fixes a bug where cache descriptors would occaisonally return a raw
value rather than a deferred.
Diffstat (limited to 'synapse/util/async_helpers.py')
-rw-r--r--synapse/util/async_helpers.py7
1 files changed, 2 insertions, 5 deletions
diff --git a/synapse/util/async_helpers.py b/synapse/util/async_helpers.py
index 7659eaeb42..fd75ba27ad 100644
--- a/synapse/util/async_helpers.py
+++ b/synapse/util/async_helpers.py
@@ -86,11 +86,8 @@ class ObservableDeferred(object):
 
         deferred.addCallbacks(callback, errback)
 
-    def observe(self):
+    def observe(self) -> defer.Deferred:
         """Observe the underlying deferred.
-
-        Can return either a deferred if the underlying deferred is still pending
-        (or has failed), or the actual value. Callers may need to use maybeDeferred.
         """
         if not self._result:
             d = defer.Deferred()
@@ -105,7 +102,7 @@ class ObservableDeferred(object):
             return d
         else:
             success, res = self._result
-            return res if success else defer.fail(res)
+            return defer.succeed(res) if success else defer.fail(res)
 
     def observers(self):
         return self._observers