summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/__init__.py21
-rw-r--r--synapse/util/async.py20
2 files changed, 20 insertions, 21 deletions
diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py
index 4e837a918e..2da8dfa719 100644
--- a/synapse/util/__init__.py
+++ b/synapse/util/__init__.py
@@ -15,7 +15,7 @@
 
 from synapse.util.logcontext import LoggingContext
 
-from twisted.internet import reactor
+from twisted.internet import defer, reactor
 
 import time
 
@@ -45,3 +45,22 @@ class Clock(object):
 
     def cancel_call_later(self, timer):
         timer.cancel()
+
+    def time_bound_deferred(self, given_deferred, time_out):
+        ret_deferred = defer.Deferred()
+
+        def timed_out():
+            if not given_deferred.called:
+                given_deferred.cancel()
+                ret_deferred.errback(RuntimeError("Timed out"))
+
+        timer = self.call_later(time_out, timed_out)
+
+        def succeed(result):
+            self.cancel_call_later(timer)
+            ret_deferred.callback(result)
+
+        given_deferred.addCallback(succeed)
+        given_deferred.addErrback(ret_deferred.errback)
+
+        return ret_deferred
diff --git a/synapse/util/async.py b/synapse/util/async.py
index d4d1d4b472..c4fe5d522f 100644
--- a/synapse/util/async.py
+++ b/synapse/util/async.py
@@ -32,23 +32,3 @@ def run_on_reactor():
     iteration of the main loop
     """
     return sleep(0)
-
-
-def time_bound_deferred(given_deferred, clock, time_out):
-    ret_deferred = defer.Deferred()
-
-    def timed_out():
-        if not given_deferred.called:
-            given_deferred.cancel()
-            ret_deferred.errback(RuntimeError("Timed out"))
-
-    timer = clock.call_later(time_out, timed_out)
-
-    def succeed(result):
-        clock.cancel_call_later(timer)
-        ret_deferred.callback(result)
-
-    given_deferred.addCallback(succeed)
-    given_deferred.addErrback(ret_deferred.errback)
-
-    return ret_deferred