mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 09:06:06 -04:00
Refactor _get_events
This commit is contained in:
parent
36ea26c5c0
commit
cdb3757942
3 changed files with 131 additions and 261 deletions
|
@ -29,6 +29,34 @@ def unwrapFirstError(failure):
|
|||
return failure.value.subFailure
|
||||
|
||||
|
||||
def unwrap_deferred(d):
|
||||
"""Given a deferred that we know has completed, return its value or raise
|
||||
the failure as an exception
|
||||
"""
|
||||
if not d.called:
|
||||
raise RuntimeError("deferred has not finished")
|
||||
|
||||
res = []
|
||||
|
||||
def f(r):
|
||||
res.append(r)
|
||||
return r
|
||||
d.addCallback(f)
|
||||
|
||||
if res:
|
||||
return res[0]
|
||||
|
||||
def f(r):
|
||||
res.append(r)
|
||||
return r
|
||||
d.addErrback(f)
|
||||
|
||||
if res:
|
||||
res[0].raiseException()
|
||||
else:
|
||||
raise RuntimeError("deferred did not call callbacks")
|
||||
|
||||
|
||||
class Clock(object):
|
||||
"""A small utility that obtains current time-of-day so that time may be
|
||||
mocked during unit-tests.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue