mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 12:23:48 +01:00
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.
This commit is contained in:
parent
f46eee838a
commit
1c82fbd2eb
1 changed files with 19 additions and 0 deletions
|
@ -32,3 +32,22 @@ def run_on_reactor():
|
||||||
iteration of the main loop
|
iteration of the main loop
|
||||||
"""
|
"""
|
||||||
return sleep(0)
|
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
|
||||||
|
|
Loading…
Reference in a new issue