28
28
Optional ,
29
29
Tuple ,
30
30
TypeVar ,
31
+ cast ,
31
32
overload ,
32
33
)
33
34
34
35
from prometheus_client import Histogram
35
36
from typing_extensions import Literal
36
37
37
38
from twisted .enterprise import adbapi
38
- from twisted .internet import defer
39
39
40
40
from synapse .api .errors import StoreError
41
41
from synapse .config .database import DatabaseConnectionConfig
@@ -507,8 +507,9 @@ def new_transaction(
507
507
self ._txn_perf_counters .update (desc , duration )
508
508
sql_txn_timer .labels (desc ).observe (duration )
509
509
510
- @defer .inlineCallbacks
511
- def runInteraction (self , desc : str , func : Callable , * args : Any , ** kwargs : Any ):
510
+ async def runInteraction (
511
+ self , desc : str , func : "Callable[..., R]" , * args : Any , ** kwargs : Any
512
+ ) -> R :
512
513
"""Starts a transaction on the database and runs a given function
513
514
514
515
Arguments:
@@ -521,7 +522,7 @@ def runInteraction(self, desc: str, func: Callable, *args: Any, **kwargs: Any):
521
522
kwargs: named args to pass to `func`
522
523
523
524
Returns:
524
- Deferred: The result of func
525
+ The result of func
525
526
"""
526
527
after_callbacks = [] # type: List[_CallbackListEntry]
527
528
exception_callbacks = [] # type: List[_CallbackListEntry]
@@ -530,16 +531,14 @@ def runInteraction(self, desc: str, func: Callable, *args: Any, **kwargs: Any):
530
531
logger .warning ("Starting db txn '%s' from sentinel context" , desc )
531
532
532
533
try :
533
- result = yield defer .ensureDeferred (
534
- self .runWithConnection (
535
- self .new_transaction ,
536
- desc ,
537
- after_callbacks ,
538
- exception_callbacks ,
539
- func ,
540
- * args ,
541
- ** kwargs
542
- )
534
+ result = await self .runWithConnection (
535
+ self .new_transaction ,
536
+ desc ,
537
+ after_callbacks ,
538
+ exception_callbacks ,
539
+ func ,
540
+ * args ,
541
+ ** kwargs
543
542
)
544
543
545
544
for after_callback , after_args , after_kwargs in after_callbacks :
@@ -549,7 +548,7 @@ def runInteraction(self, desc: str, func: Callable, *args: Any, **kwargs: Any):
549
548
after_callback (* after_args , ** after_kwargs )
550
549
raise
551
550
552
- return result
551
+ return cast ( R , result )
553
552
554
553
async def runWithConnection (
555
554
self , func : "Callable[..., R]" , * args : Any , ** kwargs : Any
0 commit comments