2828 Optional ,
2929 Tuple ,
3030 TypeVar ,
31+ cast ,
3132 overload ,
3233)
3334
3435from prometheus_client import Histogram
3536from typing_extensions import Literal
3637
3738from twisted .enterprise import adbapi
38- from twisted .internet import defer
3939
4040from synapse .api .errors import StoreError
4141from synapse .config .database import DatabaseConnectionConfig
@@ -507,8 +507,9 @@ def new_transaction(
507507 self ._txn_perf_counters .update (desc , duration )
508508 sql_txn_timer .labels (desc ).observe (duration )
509509
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 :
512513 """Starts a transaction on the database and runs a given function
513514
514515 Arguments:
@@ -521,7 +522,7 @@ def runInteraction(self, desc: str, func: Callable, *args: Any, **kwargs: Any):
521522 kwargs: named args to pass to `func`
522523
523524 Returns:
524- Deferred: The result of func
525+ The result of func
525526 """
526527 after_callbacks = [] # type: List[_CallbackListEntry]
527528 exception_callbacks = [] # type: List[_CallbackListEntry]
@@ -530,16 +531,14 @@ def runInteraction(self, desc: str, func: Callable, *args: Any, **kwargs: Any):
530531 logger .warning ("Starting db txn '%s' from sentinel context" , desc )
531532
532533 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
543542 )
544543
545544 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):
549548 after_callback (* after_args , ** after_kwargs )
550549 raise
551550
552- return result
551+ return cast ( R , result )
553552
554553 async def runWithConnection (
555554 self , func : "Callable[..., R]" , * args : Any , ** kwargs : Any
0 commit comments