mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 10:46:06 -04:00
Move .observe() up to the cache to make things neater
This commit is contained in:
parent
8ecaff51a1
commit
af4a1bac50
3 changed files with 11 additions and 33 deletions
|
@ -67,19 +67,18 @@ class HttpTransactionCache(object):
|
|||
txn_key (str): A key to ensure idempotency should fetch_or_execute be
|
||||
called again at a later point in time.
|
||||
fn (function): A function which returns a tuple of
|
||||
(response_code, response_dict)d
|
||||
(response_code, response_dict).
|
||||
*args: Arguments to pass to fn.
|
||||
**kwargs: Keyword arguments to pass to fn.
|
||||
Returns:
|
||||
synapse.util.async.ObservableDeferred which resolves to a tuple
|
||||
of (response_code, response_dict).
|
||||
Deferred which resolves to a tuple of (response_code, response_dict).
|
||||
"""
|
||||
try:
|
||||
return self.transactions[txn_key]
|
||||
return self.transactions[txn_key].observe()
|
||||
except KeyError:
|
||||
pass # execute the function instead.
|
||||
|
||||
deferred = fn(*args, **kwargs)
|
||||
observable = ObservableDeferred(deferred)
|
||||
self.transactions[txn_key] = observable
|
||||
return observable
|
||||
return observable.observe()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue