diff options
author | Erik Johnston <erik@matrix.org> | 2015-04-27 13:59:37 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-04-27 13:59:37 +0100 |
commit | 1c82fbd2eb99d689d8fe835eca9f394518e25316 (patch) | |
tree | 387651aa71c3cffd4e6e0dde3012636df50db576 /synapse/util | |
parent | Add note about updating your signing keys (ie. "the auto thing") (diff) | |
download | synapse-1c82fbd2eb99d689d8fe835eca9f394518e25316.tar.xz |
Implement create_observer.
`create_observer` takes a deferred and create a new deferred that *observers* the original deferred. Any callbacks added to the observing deferred will *not* affect the origin deferred.
Diffstat (limited to 'synapse/util')
-rw-r--r-- | synapse/util/async.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/synapse/util/async.py b/synapse/util/async.py index c4fe5d522f..d8febdb90c 100644 --- a/synapse/util/async.py +++ b/synapse/util/async.py @@ -32,3 +32,22 @@ def run_on_reactor(): iteration of the main loop """ return sleep(0) + + +def create_observer(deferred): + """Creates a deferred that observes the result or failure of the given + deferred *without* affecting the given deferred. + """ + d = defer.Deferred() + + def callback(r): + d.callback(r) + return r + + def errback(f): + d.errback(f) + return f + + deferred.addCallbacks(callback, errback) + + return d |