diff --git a/changelog.d/8156.misc b/changelog.d/8156.misc new file mode 100644 index 000000000000..dfe4c03171d6 --- /dev/null +++ b/changelog.d/8156.misc @@ -0,0 +1 @@ +Convert various parts of the codebase to async/await. diff --git a/synapse/storage/database.py b/synapse/storage/database.py index 7ab370efef15..41d2291e848a 100644 --- a/synapse/storage/database.py +++ b/synapse/storage/database.py @@ -35,7 +35,6 @@ from typing_extensions import Literal from twisted.enterprise import adbapi -from twisted.internet import defer from synapse.api.errors import StoreError from synapse.config.database import DatabaseConnectionConfig @@ -507,8 +506,9 @@ def new_transaction( self._txn_perf_counters.update(desc, duration) sql_txn_timer.labels(desc).observe(duration) - @defer.inlineCallbacks - def runInteraction(self, desc: str, func: Callable, *args: Any, **kwargs: Any): + async def runInteraction( + self, desc: str, func: Callable, *args: Any, **kwargs: Any + ) -> Any: """Starts a transaction on the database and runs a given function Arguments: @@ -521,7 +521,7 @@ def runInteraction(self, desc: str, func: Callable, *args: Any, **kwargs: Any): kwargs: named args to pass to `func` Returns: - Deferred: The result of func + The result of func """ after_callbacks = [] # type: List[_CallbackListEntry] exception_callbacks = [] # type: List[_CallbackListEntry] @@ -530,16 +530,14 @@ def runInteraction(self, desc: str, func: Callable, *args: Any, **kwargs: Any): logger.warning("Starting db txn '%s' from sentinel context", desc) try: - result = yield defer.ensureDeferred( - self.runWithConnection( - self.new_transaction, - desc, - after_callbacks, - exception_callbacks, - func, - *args, - **kwargs - ) + result = await self.runWithConnection( + self.new_transaction, + desc, + after_callbacks, + exception_callbacks, + func, + *args, + **kwargs ) for after_callback, after_args, after_kwargs in after_callbacks: